Number Guesser always return false

Here my compareGuesses function always return false what’s the problem in my logic i don’t understand.

let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
let userGuess = 5;
let computerGuess = Math.floor(Math.random() * 9);

// Write your code below:
const generateTarget = () => {
  return Math.floor(Math.random() * 9);

let target = generateTarget();
const compareGuesses = (userGuess, computerGuess, target) => {
    //let valueH = Math.abs(userGuess - target);
    //let valueC = Math.abs(computerGuess - target);

    if((Math.abs(userGuess - target)) <= (Math.abs(computerGuess - target))) {
      return true;
    } else {
      return false;

const winner = compareGuesses(userGuess, computerGuess, target) === 'true' ? 'human' :  'computer';
const updateScore = (winner) => {
  if(winner === 'human') {
    humanScore += 1;
  } else if(winner === 'computer') {
    computerScore += 1;
  } else {
    console.log('Error: something might be wrong');


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


I think this might be the problem.

Your compareGuesses() function is set to return either true or false. Later on, you assign the variable winner to the result of calling your compareGuesses() function, which means winner will now hold a Boolean value (either true or false).

But then inside your updateScore() function, you’re trying to check if winner has the value ‘human’ or ‘computer assigned to it. That’s not gonna work, since the winner value will NEVER hold either of those values. It will always hold either true or false.

Hope this helped you :slightly_smiling_face:

Is the problem with compareGuesses() If condition logic… :thinking:

First of all, I’m truly sorry for what I said before, because I just realized that wasn’t the problem :sweat:

What’s the output when you run your code?

look at your compareGuesses

if () {

compareGuesses() output is always show else part output false.

I look it many times but i don’t find the problem pls help me

see if this helps, I don’t have notes for that project, or pro access, so a bit blind here.