# Number Guesser Project Help

Hello everyone!

This is my first post on the community forum. If I missed anything from the guidelines about proper posting, please let me know and I will adjust to make it better.

I am currently working on the ‘Number Guesser’ project in JavaScript and I have my code done but not sure why its not working. Everything seems to be right? Here’s my code:

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

const generateTarget =() => { // Generate new secret number between 0 and 9

``````return Math.floor(Math.random() * 10);
``````

}

const compareGuesses = (humanGuess, computerGuess, targetNum) => { //determine which guess is closest to the target number

``````let humanDiff = Math.abs((humanGuess - targetNum));

let computerDiff = Math.abs((computerGuess - targetNum));
``````

if (humanDiff <= computerDiff) {

return true

}

else {

return false

}

const updateScore = (winner) => {

if (winner ===‘human’) {

humanScore =+ 1

}

if (winner ===‘computer’) {

computerScore =+ 1

}

const advancedRound = () => {

currentRoundNumber =+ 1

}

}

1 Like

Hello, @byteblaster50224, and welcome to the forums.

Does these look right? The code that calls your functions is in a file called `game.js`. The function below isn’t named correctly, and likely causes your game to crash. If you open your browser console, you should see an error like: `Uncaught ReferenceError: advanceRound is not defined`

Also, please review How do I format code in my posts?

1 Like
``````let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

const generateTarget =() => { // Generate new secret number between 0 and 9

return Math.floor(Math.random() * 10);

}

const compareGuesses = (humanGuess, computerGuess, targetNum) => { //determine which guess is closest to the target number

let humanDiff = Math.abs((humanGuess - targetNum));

let computerDiff = Math.abs((computerGuess - targetNum));

if (humanDiff <= computerDiff) {

return true;

}

else {

return false;

}

const updateScore = (winner) => {

if (winner ==='human') {

humanScore = humanScore++;

}

if (winner ==='computer') {

computerScore = computerScore++;

}

const advanceRound = () => {

currentRoundNumber = currentRoundNumber++;

}

}
``````

Thank you! I looked at the guideline for formatting and I believe I did it right. Please bare with me as I learn the ropes.

As far `currentRoundNumber =+ 1`, I re wrote it to be clearer for me to read. I am still having issues running it and not sure where the bug is … Blockquote

1 Like

`=+` is not an operator. It is the assignment operator followed by a plus sign, so you are assigning your variables to a positive `1`. If you want to increment a variable, you have several options:

``````let myValue = 0;
myValue++;
myValue += 1;
myValue = myValue + 1;
//add a value other than 1:
myValue += 5
//or:
myValue = myValue + 5
``````

Edit: Oops! Didn’t realize you had already updated your code to use `variable++`.
Edit #2: Didn’t look closely enough:

The above probably isn’t doing what you think it should be doing. Compare your code to my examples above. See Increment (++) - JavaScript | MDN for more information.

Here's a brief example of what happens when using the increment operator as you have above:
``````let x = 3;
x = x++;
console.log(x); //x is still 3
x = x++;
console.log(x); //what is printed?
x = x++;
console.log(x); //what is printed now?
``````

Output:

3
3
3

If there are issues other than your scores and round number not updating, try opening your browser console. Refresh the page, and try playing the game. Do you see any error messages in the console?