Questions about number guesser

Hi,

I am working on the number guesser and have some questions:

If I do not win, there is no message and I can just click “Make a Guess” again until I win. This must be a mistake I made somewhere right? This way the computer has 0 wins.

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

// Write your code below:

const generateTarget = () => {
  return Math.floor(Math.random() * 10)
};

  
const compareGuesses = (humanGuess, computerGuess, targetGuess) => {
   
    const humanDiff = getAbdoluteDistance (humanGuess, targetGuess);
    const computerDiff = getAbdoluteDistance (computerGuess, targetGuess);

if (computerDiff >= humanDiff) {
  return true
} else {
  return false
};

};

const updateScore = winner => {
  if (winner === 'human') {
    humanScore ++;
  }
  if (winner === 'computer') {
    computerscore ++;
  }
};


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


const getAbdoluteDistance =  (a1, a2) => {
  return (Math.abs ((a1 -a2)));
}

const alertMessage = (userGuess) => {
  if (userGuess  > 9 || userGuess < 0) {
    alert ('Guess must be between 0 & 9')
  }
}

Hey there @datemathomas!!

Is this all of your code?

Currently it seems to be missing something to tie everything together and run the functions, and there are no console.log() so the user gets no messages.
Also could you post a link to the lesson/project?

1 Like

Here is the project link

Ahh, makes much more sense now.

Have you used developer tools before? If so check your console for errors.

If you don't know how to use Dev Tools

Here is the error being reported:

script.js:34 Uncaught ReferenceError: computerscore is not defined
    at updateScore (VM18 script.js:34)
    at HTMLButtonElement.<anonymous> (VM15 game.js:33)

Though this may seem unconnected to your problem, if you take a look at how game.js is written, you see that this causes a whole function to stop before it can display that the computer won.