Number guesser in javascript

I don’t know whats wrong with my code. only Target number, computer guess gets generated (human guess i am able to type, do + and -)
1)scores of human and computer does not get updated .
2)round number also does not get updated
3)next round button does not get enabled.
4) the statement who won also wont appear.
my code is as follows

let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;

// Write your code below:

function generateTarget(){
  return Math.floor(Math.random()*9);

}
 const compareGuess =(humanGuess, computerGuess, secrettarget) =>{ 
  if ((Math.abs(humanGuess - secrettarget)) <= (Math.abs(computerGuess - secrettarget)))
  {
      console.log("target :" +generateTarget());
      console.log('humanGuess: ' + humanGuess); //8
      console.log('computerGuess: ' + computerGuess);//3
      console.log('Result Math.abs(secrettarget - humanGuess):'  + Math.abs(secrettarget - humanGuess));//no proper out put
     return true;
  }
  else 
  {
    console.log("target :" +generateTarget());
      console.log('humanGuess: ' + humanGuess); //8
      console.log('computerGuess: ' + computerGuess);//3
      console.log('Result Math.abs(secrettarget - computerGuess):'  + Math.abs(secrettarget - computerGuess));//no proper result
  return false;
  }
 }

  console.log('The return value of compareGuess is: ' + compareGuess(8, 3, generateTarget()));//no matter what type case it remains true
 function updateScore(compareGuess){
     if(compareGuess=== true)
      humanScore++;
      else 
      computerScore++;
     
 };
 function advanceRound(){
     currentRoundNumber++
 }
 console.log(humanScore);// no matter what type of case it remains 0,tried giving with in updateScore(compareGuess) not getting exexuted.
 console.log(computerScore);//no matter what type of case it remains 0,tried giving with in updateScore(compareGuess) not getting exexuted.

sorry if these are beginner level questions but i have tried for one week. :sweat_smile: :sweat_smile: but still no result

Have you tried checking in the console when you press the Make a Guess button? It points you in the right direction.

If you need further help:

Your compareGuess function is named incorrectly, it needs to be compareGuesses

1 Like

That helped me thanks a lot but my doubt did not get clarified .
How come it worked when I changed it to compareGuesses from compareGuess.
Because I have initialized const compareGuess
But really sir thanks a lot🤗

Well, you’re right here:

You have declared the comperGuess function, which means it can be used. compareGuesses was never defined, meaning JS doesn’t know what to do when it is called, thus it throws an error.

1 Like

compareGuess() did not work because in the game.js file, specifically line 29, it is trying to call compareGuesses(). As codeneutrino pointed out, you did not define compareGuesses().

 // Determine if the human or computer wins:
  const humanIsWinner = compareGuesses(currentHumanGuess, computerGuess, target)

If the functions are not named the same throughout the files things will break. Hope that helps!

1 Like

Thank u that cleared my doubt :+1: