Number Guesser Challenge Project (JavaScript)

My solution:

hi can someone help interpret this alert() on Number guessing game…

You probably calculated the distance from the computer guess to the target and from the human guess to the target. Move this into a separate getAbsoluteDistance() function that takes two numbers and returns the distance, and then use that inside your compareGuesses() function.
Add functionality to check whether the user guess is between 0 and 9 and alert() the user that their number is out of range. It’s not possible to set a number outside this range with the + and = buttons, but users can do so by typing directly in the input field.

Just finished the project. My first time using the .alert() function. :laughing:
Let me know if you see any improvement.

Here is my code:

1 Like

I think it means that change the function by using alert() so if a user enters a number outside of 0 and 9, then the browser will prompt the user that your number is not between 0 and 9.
I just posted my code. You can check it out see if that helps.

1 Like

Hello, i just completed this project like 5minutes ago. I was struggling when it came to the compareGuesses function but I i actually jumped on the forum and sought out the different solutions other had found until it clicked. The solution was much simpler than I was anticipating which I think was adding to my anxiety in the project. Ultimately I completed the project and gained a more solid understanding of functions and comparing multiple parameters.

Hey guys,

Here’s my hopeful attempt at this project - I can’t see anything wrong with it and it seems to work fine but if you have any tips, feel free to let me know. :upside_down_face:


Note: I added the alert() functionality to the game.js file.

Finished site:

My Number Guesser works fine but it does not update the score. I think I messed up my updateScore function.

why when i use">" the below"if" statement stop working?

Here is my code for the challenge. Game is working as required. Only issue that is persisting is that after the alert() is called, the program still runs declaring computer as winner. It would be of great help if anyone could suggest a way to stop the program if alert() is called.

Had to restart the project as was having some problems, but all seems to be working well now.

With included extensions prompts.

You have a typo in the conditional on line 8:


On line 9, you should use “==” or"===" instead of “=” since a single equals is for assigning a variable not comparisons:

if(userGuess=computerGuess){return true;}

Hi everyone!

I’m kinda confused with task 8, my code is not working properly, could someone explain me why? It always turns the computer into a winner whatever the number it displays…

Thank you!

Hi! I am on objective 4, but I can’t seem to understand where am I going wrong? Can anyone help me with this please, or help me understand where am I going wrong? Thank you

let humanScore = 0;

let computerScore = 0;

let currentRoundNumber = 1;

const generateTarget = () => {

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



const compareGuesses = (humanGuess, computerGuess, targetNumber) => {

let humanGuess = humanGuess - targetNumber;

let computerGuess = computerGuess - targetNumber;

if ((humanGuess === computerGuess) || (humanGuess < computerGuess&&targetNumber)) { 

  return true;

else {

  return false;





The error I get is:
let humanGuess = humanGuess - targetNumber;
SyntaxError: Identifier ‘humanGuess’ has already been declared
at createScript (vm.js:53:10)
at Object.runInThisContext (vm.js:95:10)
at Module._compile (module.js:543:28)
at Object.Module._extensions…js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
at run (bootstrap_node.js:427:7)
at startup (bootstrap_node.js:151:9)