Skip to content

How to make a function in Node JS run only once

I am creating a simple tictactoe terminal game in JS. I use the variable named player1Input to get user prompt. If the prompt is not equal to “X”, I call the function again to make sure the user input the right input. If I enter the wrong input multiple times, the function (player1Game) ends up be…

Fetching JSON and rendering it with react

My fetch gives me the following JSON: “{“name”:”John”,”age”:26,”city”:”London”}” However when i try to render it on my page like this: I get a TypeError: Cannot read property ‘map’ of undefined How can i fix this? Thanks in ad…

cannot use import statement outside a module error

So I have a file and it contains a function my main.js: and for some reason I still get an error Uncaught SyntaxError: Cannot use import statement outside a module Answer Using in Node.js Add “type”: “module” to your package.json. This will tell node that import will be used to import …

use getStaticProps in component

I started a project with next js and typescript. I have a main component that I call it in the index.js page I use the getStaticProps function in the main component getStaticProps returns a prop object and when I log this prop in my main component I received undefined in my console. I want to know using the g…

limit the array length by 2 data only

I am currently making a matchmaking system. My target is to limit the array length by 2 data only. In my current work, when I add another data with the same level, it becomes 3 data in 1 array (Please see pic 1). When there’s 3 data in 1 array, send the extra 1 data to another array until it