Number Guessing Game help

Hiya, I’m having some issues with the code below. Whenever I play the game the computer always wins and is added to score even when the human should win. I don’t understand why it keeps returning false. Please help, thank you.

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

// Write your code below:

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

}

const compareGuesses = (human, computer, target) => {
  target= generateTarget;
  if (Math.abs(target - human) < Math.abs(target - computer)) {
    return true;
    }
  if (Math.abs(target - human) === Math.abs(target- computer)) {
    return true;} 
else {
return false 
}
}

const updateScore = winner => {
  winner = compareGuesses;
   if (winner === 'human'){
  humanScore = humanScore + 1
   }
   else {
     computerScore += 1;
     }
     
}
  const advanceRound = currentRoundNumber =>{
  currentRoundNumber =   currentRoundNumber += 1
  } 

here:

target = generateTarget;

you are merely referencing the function, you don’t call/invoke the function, so target will now contain the function object.

this bug is clearly caused by something going wrong in your comparison. so you could add console.log() to see the values used in your comparison

you could also use <= in the comparison, then one if condition/clause is enough.

omg thank you! I took out
target = generateTarget;
and it works now. :woman_facepalming:
Now I just have to work out why it is not adding high score to human, guess that is a referencing issue or something too?

you were overwriting the parameter. That is indeed not a good idea. I should pay more attention, I saw one problem, but seems there was more then one problem

same issue:

winner = compareGuesses;

you overwrite the parameter (winner). Overwriting the parameter will render the argument at function call useless.

Yep I took that out too as realised that was causing an issue from what was said before. Still not getting it to add to human score and computer is jumping from 0 to 2.

You have made some changes, could you post your full code again and the exercise url? For me to be able to run the code makes debugging a lot easier.

I managed to fix it so it doesn’t keep adding to computer and now is working as it should apart from the jump from 0 to 2. It happens now on both when they win their first round. Is there another way than += 1 as +1 doesn’t add anything to it either and ++ didn’t work for me as well unless I am doing wrong somewhere

const updateScore = winner => {
   if (winner === 'human' ){
 humanScore += 1
   }
   else {
     computerScore += 1;
     }
     
}

I found a solution in just putting this

const updateScore = winner => {
   if (winner === 'human' ){
 humanScore +=1;
   }
   else {
     computerScore++;
     }

not sure why it only works when its written like this but it does.