Number guesser buttons wont work

Heres my code from the number guesser challenge. When I run the website the buttons don’t work.

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

// Write your code below:

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

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

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

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


Hello, I do not know JS to be honest but after looking at your code for bit, I think I found your issue but I can’t be sure obviously since I have not learned JS yet.

On the line - } else if ((Math.abs(human - target)) > (Math.abs(computer - target))) {
return false

I believe you forgot to add an “;” at the end of “false” like you did on the others. Hope this helped, if not then I apologize, sorry for using your time.

It’s really helpful if you provide a link for the thing you’re working on so we can see the full context.

The generateTarget function is missing a return .

1 Like

You can also do it as an implicit return in this case:

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

Then you don’t even need the actual “return”.

1 Like

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