Python or C++ Program to Find LHS = RHS

I’ve been Given a Question to find If 23=5 LHS ..i.e 2+3 = 5 … Since it’s true it should return true else Return -1

Note that the Input is single input 23=5 in a single sentence.

I have no idea how to differentiate the left side of = and right side of the =.

How to load the code from page 2 on page 1 when the button is clicked?

code page1.html:

<script class="scriptthis">
some code
</script>
<div id="content">
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</div>
<button id="load-more">Load More Button</button>
<script>
$( "#load-more" ).click(function() {
  $('script... or near').load('page2.html... script code or script
  $('#content').load('page2.html... content
});
</script>

code page2.html:

<script class="scriptthis">
some code another
</script>
<div id="content">
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
<div class="card"></div>
</div>

How to load the code from page 2 on page 1 when the button is clicked?
Script to script or near – is the main problem.
and content to the end #content div

Please help with a working solution.

closure and settimeout question in for loop [duplicate]

Can someone tell the outputs of the following code.
I just want to print 1 2 3 4 5 on the console after 1s

1)

for (var i = 0; i < 5; ++i){
    setTimeout(() =>{
        console.log(i);
    }, 1000);
}

for (let i = 0; i < 5; ++i){
    setTimeout(() =>{
        console.log(i);
    }, 1000);
}

for (let i = 0; i < 5; ++i){
    setTimeout((i) =>{
        console.log(i);
    }, 1000);
}

All of them are giving different answer and i dont know why. Please help!!

net::ERR_CONNECTION_REFUSED, RapidAPI, trying to fetch the solveSudoku API

I’m using an API that solves the Sudoku game. If I understand it right my issue is fetching the data from the API. The API is returning data. I have also tried without the backend and received the 400 bad request error. I’m quite new to programming and would need your help, please.

Here is the link to the error message https://imgur.com/a/brFk7Oo

Here is the link to the network error https://imgur.com/PsBsefW

app.js

    // Selectors
const puzzleBoard = document.querySelector('#puzzle');
const solveButton = document.querySelector('#solve-button');
const solutionDisplay = document.querySelector('#solution');
const squares = 81;
let submission = [];

//functions
for (let i = 0; i < squares; i++) {
    const inputElement = document.createElement('input');
    inputElement.setAttribute('type', 'number');
    inputElement.setAttribute('min', '1');
    inputElement.setAttribute('max', '9');
    if (
        ((i % 9 == 0 || i % 9 == 1 || i % 9 == 2) && i < 21) ||
        ((i % 9 == 6 || i % 9 == 7 || i % 9 == 8) && i < 27) ||
        ((i % 9 == 3 || i % 9 == 4 || i % 9 == 5) && (i > 27 && i < 53)) ||
        ((i % 9 == 0 || i % 9 == 1 || i % 9 == 2) && i > 53) ||
        ((i % 9 == 6 || i % 9 == 7 || i % 9 == 8) && i > 53) 
    ) {
        inputElement.classList.add('odd-section')
    }

    puzzleBoard.appendChild(inputElement);
}

// wrapped the document in a new div
const wrapper = document.createElement('div')
puzzleBoard.parentNode.insertBefore(wrapper, puzzleBoard)
wrapper.appendChild(puzzleBoard)

wrapper.className = "puzzle"


const joinValues = () => {
    const inputs = document.querySelectorAll('input');
    inputs.forEach(input => {
        if (input.value) {
            submission.push(input.value);
        } else {
            submission.push('.');
        }
    })
    console.log(submission)
}


const populateValues = (isSolvable, solution) => {
    const inputs = document.querySelectorAll('input');
    if (isSolvable && solution) {
        inputs.forEach((input, i) => {
            input.value = solution[i];
        })
        solutionDisplay.innerHTML = 'Here is the answer!';
    } else {
        solutionDisplay.innerHTML = 'You made a mistake, this is not solvable';
    }

}

const solve = () => {
    joinValues()
    const data = {numbers: submission.join('')}
    console.log('data', data)

    fetch('http://localhost:8000/solve', {
        method: 'POST', 
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json'
        }, 
        body: JSON.stringify(data)
    })  .then(response => response.json())
        .then(data => {
            console.log(data)
            populateValues(data.solvable, data.solution)
            submission = []
    })
    .catch((error) => {
        console.error('Error:', error)
    })
}

solveButton.addEventListener('click', solve);

server.js

    const PORT = 8000
const axios = require('axios').default
const express = require('express')
const cors = require('cors')
require('dotenv').config()
const app = express()
app.use(cors())
app.use(express.json())

app.post('/solve', (req, res) => {
    const options = {
        method: 'POST',
        url: 'https://solve-sudoku.p.rapidapi.com/',
        headers: {
            'content-type': 'application/json',
            'x-rapidapi-host': 'solve-sudoku.p.rapidapi.com',
            'x-rapidapi-key': process.env.RAPID_API_KEY 
        },
        data: {
            puzzle: req.body.numbers
        }
    }

    axios.request(options).then((response) => {
        console.log(response.data)
        res.json(response.data)
    }).catch((error) => {
        console.error(error)
    })
})

app.listen(PORT, () => console.log(`server listening on PORT ${PORT}`))

Would really appreciate any help

Getting error on await act() JEST. Async callback was not invoked within the 5000ms timeout specified by jest.setTimeout.Timeout

I am new to unit testing and jest, and was stuck at a scenario where the react’s state are being set asynchronously after API call is resolved or rejected. I found some answers in which they’ve mentioned to use waitFor or await act(async()=>{}). Whenever I’m trying to await with act or even async act, I’m getting this error and the tests are failing. I’ve tried to replicate a similar scenario below.
If these ways of handling async updates to component are not correct, then what could be the other solutions. I’m using react hooks to set the state after api resolves or rejects.

React and react-dom version : 16.8

test('new ', async () => {
  await act(() => {
    console.log('test');
  });
  expect('temp').toBe('temp');
});

I can’t build angular project

when i try to build angular project with command ng build –prod
i faced below error
An unhandled exception occurred: Transform failed with 1 error:
error: Invalid version: “15.2-15.3”

[error] HookWebpackError: Transform failed with 1 error:
error: Invalid version: “15.2-15.3”
at makeWebpackError (node_moduleswebpacklibHookWebpackError.js:48:9)
at node_moduleswebpacklibCompilation.js:3055:12
at eval (eval at create (node_modulestapablelibHookCodeFactory.js:33:10), :98:1)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
— inner error —
Error: Transform failed with 1 error:
error: Invalid version: “15.2-15.3”
at failureErrorWithLog (node_modules@angular-devkitbuild-angularnode_modulesesbuildlibmain.js:1557:15)
at node_modules@angular-devkitbuild-angularnode_modulesesbuildlibmain.js:1346:29
at node_modules@angular-devkitbuild-angularnode_modulesesbuildlibmain.js:637:9
at handleIncomingPacket (node_modules@angular-devkitbuild-angularnode_modulesesbuildlibmain.js:734:9)
at Socket.readFromStdout (node_modules@angular-devkitbuild-angularnode_modulesesbuildlibmain.js:604:7)
at Socket.emit (events.js:400:28)
at addChunk (internal/streams/readable.js:293:12)
at readableAddChunk (internal/streams/readable.js:267:9)
at Socket.Readable.push (internal/streams/readable.js:206:10)
at Pipe.onStreamRead (internal/stream_base_commons.js:188:23)

How to access object properties before inizialization in JavaScript/ Typescript?

I need to create a “Themes” object, which should contain all the themes with the colors I need for an app. I would like to use some of its variables to change its others. For example, having the “disabled” property set to the text color of the object + some opacity.
I tried to achieve this by using this.variableName in template literals strings but I get an error saying I can’t access it before initialization.
Is there any way to achieve this without having to copy-paste the text each time manually?

Code sample:

const Themes = {
    Dark: {
        isDark: true,
        BackgroundColors: {
          primary: '#622BFF',
          page: '#080246',
          floating: '#1C1A70',
          error: '#FF004F',
          warning: '#FCE35E',
          success: '#2ACF58',
          // I thought adding ${this.variableName} would have worked but unfortunately it doesn't
          menu: `linear-gradient(180deg, ${this.Dark.BackgroundColors.floating} 0%, 
                 rgba(242, 24, 155, 0.9) 12%,  ${this.Dark.BackgroundColors.floating} 100%)`,
          
        },
        ContentColors: {
          shared: '#622BFF',
          text: '#FFFFFF',
          //adding 99 for opacity
          disabled: `${this.Dark.ContentColors.text}99`,
          inverted: '${this.Dark.BackgroundColors.page}',
        },
      },
      Light:{
          ......
      }
}

How to update Vuex Store from a class/object I created

I am building an object/class factory that creates and handles devices (example – Bluetooth device – read, write, connect, etc).

I do not want to add the object to the vuex store due to potential mutations (talking from past experiences), and prefer to manage/update variables in the store from within the class.

What is the common practice to do that? if possible.

class BluetoothObj extends someVuexClassMaybe{...

If not, are there any recommendations?

class BluetoothObj {
    constructor() {
        console.log('created bluetooth device')
    }

    connect() {

    }

    read() {
        
    }

    write() {

    }

    updateStore() {
        
    }
}

Tone.js + React.js – How to start playing multiple players simultaneously on button click using the Tone.Players method instead of Tone.Player?

I’m attempting to refactor this code to make it more DRY. How can I start the playback of the tracks using the Tone.Players method? codesandbox – https://codesandbox.io/s/tone-mixer-2-lyeqqz

  let player = {};
  for (let i = 0; i < tracks.length; i++) {
    player["buffers" + playerNum] = buffers["track" + playerNum];
    playerNum++;
  }

  const players = new Tone.Players(player);

  console.log("playerName:", players.player.name); // player

  players.player("player").start(); // Uncaught Error: No Player with the name player exists on this object

How to loop through an array after an interval of 5 second for every value in the array?

      const array = [
        "aplus",
        "ant",
        "bean",
        "cookie",
        "corncob",
        "corndog",
        "potato",
        "skunk",
        "rabbit",
        "duck",
        "deer",
        "boar",
        "dragon",
        "seaweed",
        "fish",
        "rarefish",
        "exoticfish",
        "jellyfish",
        "legendaryfish",
        "kraken",
        "junk",
        "garbage",
        "trash",
        "worm",
        "ladybug",
        "stickbuy",
        "spider",
        "banhammer",
        "musicalnote",
        "energydrink",
        "memepills",
        "lawdegree",
        "vaccine",
        "beakerofsusfluid",
        "ectoplasm"
      ];
      array.forEach(item => console.log(item));

Is there a way to log all the items in the array after an interval of 5 seconds for each item?

When I try to use an setTimeout function it sends the first value after 5 second and after that it sends all the other values at once..

Slider Revolution 5.3.1: Uncaught TypeError: Cannot set properties of undefined (setting ‘cssText’)

I have this problem with a wordpress website using a hard-coded slider revolution plugin v5.3.1 + acf combo where the slider doesn’t load and I keep getting a console error which says:

VM192 jquery.themepunch.tools.min.js:104 Uncaught TypeError: Cannot set properties of undefined (setting 'cssText')
at VM192 jquery.themepunch.tools.min.js:104:1873
at Function.<anonymous> (VM192 jquery.themepunch.tools.min.js:104:1931)
at q.check (VM192 jquery.themepunch.tools.min.js:60:822)
at new q (VM192 jquery.themepunch.tools.min.js:60:1176)
at a._gsDefine (VM192 jquery.themepunch.tools.min.js:60:1226)
at VM192 jquery.themepunch.tools.min.js:104:187
at VM192 jquery.themepunch.tools.min.js:105:8674

The wordpress version is updated to ver. 5.9.1 and I downgraded the jQuery version is to 1.12.4.

The site is https://woodlandsvalencia.com/

This is the Slider + ACF code used:

<ul>
                            <?php
                            $cnt = 0;
                            if(get_field('home_banner', '2')) {
                            while(the_repeater_field('home_banner', '2')){
                            $bannerimage = get_sub_field('banner_image', '2');
                            $bannertitle = get_sub_field('banner_title', '2');
                            $bannertext = get_sub_field('banner_text', '2');
                            $bannerbuttontext = get_sub_field('banner_button_text', '2');
                            $bannerbuttonlink = get_sub_field('banner_button_link', '2');
                            $cnt++;
                            ?>
                        
                        <li data-index="rs-<?=$cnt?>" data-transition="fade" data-slotamount="default" data-hideafterloop="0" data-hideslideonmobile="off" data-easein="default" data-easeout="default" data-masterspeed="300" data-thumb="#" data-rotate="0" data-saveperformance="off" data-title="Slide" data-param1="" data-param2="" data-param3="" data-param4="" data-param5="" data-param6="" data-param7="" data-param8="" data-param9="" data-param10="" data-description="">
                                <div class="tp-caption   tp-resizeme" id="slide-1-layer-9" data-x="135" data-y="" data-width="['none','none','none','none']" data-height="['none','none','none','none']" data-type="image" data-responsive_offset="on" data-frames='[{"delay":10,"speed":600,"frame":"0","from":"opacity:0;","to":"o:1;","ease":"Power3.easeInOut"},{"delay":"wait","speed":300,"frame":"999","to":"opacity:0;","ease":"Power3.easeInOut"}]' data-textAlign="['inherit','inherit','inherit','inherit']" data-paddingtop="[0,0,0,0]" data-paddingright="[0,0,0,0]" data-paddingbottom="[0,0,0,0]" data-paddingleft="[0,0,0,0]" style="z-index: 5;"><img src="<?=$bannerimage?>" alt="" data-ww="1410px" data-hh="948px" width="1410" height="948" data-no-retina>
                                </div>
                                <div class="tp-caption   tp-resizeme" id="slide-1-layer-1" data-x="40" data-y="280" data-width="['auto']" data-height="['auto']" data-type="text" data-responsive_offset="on" data-frames='[{"delay":100,"speed":800,"frame":"0","from":"opacity:0;","to":"o:1;","ease":"Power3.easeInOut"},{"delay":"wait","speed":300,"frame":"999","to":"opacity:0;","ease":"Power3.easeInOut"}]' data-textAlign="['inherit','inherit','inherit','inherit']" data-paddingtop="[0,0,0,0]" data-paddingright="[0,0,0,0]" data-paddingbottom="[0,0,0,0]" data-paddingleft="[0,0,0,0]" style="z-index: 6; white-space: nowrap; font-size: 80px; line-height: 80px; font-weight: 100; color: rgba(141, 110, 92, 1.00);font-family:Raleway;">
                                    <?= $bannertitle?>
                                </div>
                                <div class="tp-caption   tp-resizeme" id="slide-1-layer-2" data-x="40" data-y="380" data-width="['auto']" data-height="['auto']" data-type="text" data-responsive_offset="on" data-frames='[{"delay":150,"speed":800,"frame":"0","from":"opacity:0;","to":"o:1;","ease":"Power3.easeInOut"},{"delay":"wait","speed":300,"frame":"999","to":"opacity:0;","ease":"Power3.easeInOut"}]' data-textAlign="['inherit','inherit','inherit','inherit']" data-paddingtop="[0,0,0,0]" data-paddingright="[0,0,0,0]" data-paddingbottom="[0,0,0,0]" data-paddingleft="[0,0,0,0]" style="z-index: 7; white-space: nowrap; font-size: 70px; line-height: 68px; font-weight: 400; color: rgba(0, 0, 0, 1.00);font-family:Raleway;">
                                    <?=$bannertext?>
                                </div>
                                <a class="tp-caption rev-btn  tp-resizeme" href="<?php bloginfo('home') ?>/<?=$bannerbuttonlink?>" target="_self" id="slide-1-layer-4" data-x="40" data-y="550" data-width="['auto']" data-height="['auto']" data-type="button" data-actions='' data-responsive_offset="on" data-frames='[{"delay":200,"speed":800,"frame":"0","from":"opacity:0;","to":"o:1;","ease":"Power3.easeInOut"},{"delay":"wait","speed":300,"frame":"999","to":"opacity:0;","ease":"Power3.easeInOut"},{"frame":"hover","speed":"300","ease":"Linear.easeNone","to":"o:1;rX:0;rY:0;rZ:0;z:0;","style":"c:rgba(255, 255, 255, 1.00);bg:rgba(113, 81, 64, 1.00);bs:solid;bw:0 0 0 0;"}]' data-textAlign="['inherit','inherit','inherit','inherit']" data-paddingtop="[15,15,15,15]" data-paddingright="[32,32,32,32]" data-paddingbottom="[15,15,15,15]" data-paddingleft="[32,32,32,32]" style="z-index: 8; white-space: nowrap; font-size: 14px; line-height: 24px; font-weight: 700; color: rgba(255, 255, 255, 1.00);font-family:Playfair Display;background-color:rgba(141, 110, 92, 1.00);border-color:rgba(0, 0, 0, 1.00);outline:none;box-shadow:none;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;cursor:pointer;text-decoration: none;"><?=$bannerbuttontext?></a>
                                <div class="tp-caption   tp-resizeme" id="slide-1-layer-7" data-x="100" data-y="" data-width="['none','none','none','none']" data-height="['none','none','none','none']" data-type="image" data-responsive_offset="on" data-frames='[{"delay":250,"speed":800,"frame":"0","from":"y:-50px;opacity:0;","to":"o:1;","ease":"Power3.easeInOut"},{"delay":"wait","speed":300,"frame":"999","to":"opacity:0;","ease":"Power3.easeInOut"}]' data-textAlign="['inherit','inherit','inherit','inherit']" data-paddingtop="[0,0,0,0]" data-paddingright="[0,0,0,0]" data-paddingbottom="[0,0,0,0]" data-paddingleft="[0,0,0,0]" style="z-index: 9;"><img src="<?php bloginfo('template_url') ?>/images/home_shoes_slider_sep.png" alt="" data-ww="1px" data-hh="263px" width="1" height="263" data-no-retina>
                                </div>
                            </li>
                            
                            <?php } } ?>
                            
                        </ul>

Has anybody experienced this type of issue? May I know how you resolved it?

Thank you very much in advance!

An app that will tell a young guy to drive a car if he is eligible or not

Create an app that will tell a young guy if he is eligible to drive a car. If he is 18 tell the user that is not eligible to drive if is greater than 22 tell the user is eligible to drive, if the user is greater than 30 years old tell him to get a driver if the user is above 40 years tell the user is too old to drive if the user is above 60 tell the user should call his grandson to drive for him……The code that i have tried…..

var val = prompt (“enter Age”); const d = 22 ; switch (true) { case (d == 2): alert(“You are eligible”); break; case ( d >= 18 ): alert(“You are not eligible”); break; case (d >= 39): alert ( “Get a driver”); break; case (d >=59): alert (“is too old to drive a car” ); break; case (d > 60): alert (“Call your grandson to drive for you”); break; default: alert (“Drive”);

Any hint please

JS can’t receive JSON data from orion-ld broker, a CORS related issue occurred

I use orion-ld context brocker

{
"orionld version": "post-v1.0.0",
"orion version": "1.15.0-next",
"uptime": "0 d, 0 h, 25 m, 17 s",
"git_hash": "nogitversion",
"compile_time": "Wed Jan 26 15:58:47 UTC 2022",
"compiled_by": "root",
"compiled_in": "",
"release_date": "Wed Jan 26 15:58:47 UTC 2022",
"doc": "https://fiware-orion.readthedocs.org/en/master/"
}

If I try to request JSON data in an HTML file via JS like

var myRequest = new XMLHttpRequest();
myRequest.open("GET", "http://192.168.0.18:1028/ngsi-ld/v1/entities/urn:ngsi-ld:OffStreetParking:XXX_102700") ;
myRequest.setRequestHeader("Accept", "application/ld+json")       
myRequest.onload = function () {
    console.log(myRequest.responseText);
};
myRequest.send();

I got a error: “Access to XMLHttpRequest at ‘http://192.168.0.18:1028/ngsi-ld/v1/entities/urn:ngsi-ld:OffStreetParking:XXX_102700’ from origin ‘http://192.168.0.18’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.”

If I login to the docker container console and check the variable ORIONLD_CORS_ALLOWED_ORIGIN, it contains the necessary value “__ALL”.

What could be wrong here?

Must i specify dependencies in package json file

I just recently heard of the package.json file but all my small projects have always worked without it.
I’ve installed many npm modules globally and always use var x = require("express");“just for example” without even initializing the package.json and putting express as a dependency.

Is it really important

TypeError: option.getMember(“target) is not a function

So I made this kick command and I finished coding it. Now I am getting this error and have literally no idea how to fix it. I searched through the internet for an hour now and have still no idea where the issue is.

Here is the error:

TypeError: options.getMember is not a function
    at Object.execute (/Users/Aplex/Documents/Aplel/Commands/Moderation/kick.js:32:32)
    at Object.execute (/Users/Aplex/Documents/Aplel/Events/Interaction/interactionCreate.js:21:21)
    at Client.<anonymous> (/Users/Aplex/Documents/Aplel/Structures/Handlers/Events.js:18:54)
    at Client.emit (node:events:538:35)
    at InteractionCreateAction.handle (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/actions/InteractionCreate.js:74:12)
    at Object.module.exports [as INTERACTION_CREATE] (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/handlers/INTERACTION_CREATE.js:4:36)
    at WebSocketManager.handlePacket (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketManager.js:351:31)
    at WebSocketShard.onPacket (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketShard.js:444:22)
    at WebSocketShard.onMessage (/Users/Aplex/Documents/Aplel/node_modules/discord.js/src/client/websocket/WebSocketShard.js:301:10)
    at WebSocket.onMessage (/Users/Aplex/Documents/Aplel/node_modules/ws/lib/event-target.js:199:18)

And here is my code:

const { Client, CommandInteraction } = require("discord.js");

module.exports = {
    name: "kick",
    description: "Kick a member",
    userPermission: ["KICK_MEMBERS"],
    options: [
        {
            name: "target",
            description: "target to kick",
            type: "USER",
            required: true
        },
        {
            name: "reason",
            description: "reason for this kick",
            type: "STRING",
            required: false,
        }
    ],
    /**
     * 
     * @param {Client} client 
     * @param {CommandInteraction} interaction 
     * @param {String} args 
     */
    execute: async(client, interaction, args) => {
        const { options, member } = interaction;

        const target = options.getMember("target");
        const reason = options.getString("reason") || "No reason provided";

        if(!target.roles.highest.position >= member.roles.highest.position) return interaction.followUp({content: "You can't take action on this user as their role is higher than yours!",
    });

    await target.send(`You have been kicked from ${interaction.guild.name}, reason ${reason}`);

    target.kick(reason);

    interaction.followUp({content: `Kicked ${target.user.tag} successfully! reason: ${reason}`});
    },
};

Anyone know where the issue is here? It would be really appreciated if someone helped!