Stuck on Javascript number guesser

Hey guys, I am very new to javaScript and have been stuck on this project for a few days. I tried looking at previous questions about the project and could not find the answers I am looking for. The target number is not working, although it worked previously, leading me to believe I may have messed up somewhere later in the code? I do not think I will be able to tell if the rest is working without fixing this piece. Any help would be appreciated!

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

// Write your code below:

// called at start of each new round to generate target number
function generateTarget() {
  return Math.floor(Math.random() * 10)
} // stopped working?

// called each round to determine which guess is closest to the target number
const compareGuesses = (humanGuess, computerGuess, targetNumber) => {
 const userDistance = Math.abs(humanGuess -targetNumber)
 const computerDistance = Math.abs(computerGuess - targetNumber)
 if (humanDistance === computerDistance) {
   return true // human wins
 } else if (humanDistance > computerDistance) {
   return false // computer wins
 } else if (humanDistance < computerDistance) {
   return true // human wins
 }
}

// increase winner's score after each round
function updateScore(winner) {
  if (winner === 'human') {
    humanScore += 1; 
  } if else (winner === 'computer') {
    computerScore += 1; 
  }
}

const advanceRound = () => {
 currentRoundNumber += 1;
}



link: https://www.codecademy.com/practice/projects/number-guesser-independent-practice

1 Like

I suggest using a web browser’s console to check your code. It will show you your two bugs.

1 Like

Hi there, welcome to the forums!

Take a look at your updateScore() function… and I think you’ll see one of your problems.

The other obvious one is that the code you’ve posted doesn’t actually call the function you’re saying is broken… :slight_smile:

Edit: @midlindner has reliably informed me that there’s another file I overlooked which does make the function calls… Think it’s time for a :coffee:

3 Likes

Thank you! I had read it so many times I could not see the mistake. :grin:

1 Like

We’ve all been there. :slight_smile:

Let us know if you get stuck with anything else. :smiley:

Thank you for this tip! Used it to determine where I went wrong :grinning:

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.