Number Guesser Challenge Project (JavaScript)

The above is a comparison. What is the outcome when we compare two operands? Long pause… A boolean.

When the value is already a boolean do we need to differentiate any further?

if (a <= b) {
    return true
else
    return false
}

Above we’re taking the naive approach to return boolean literals. But why go to such extent once we understand how return works. It hands the evaluation of an expression (a value) back to the caller. If the expression yields a boolean, is that not a value?

return a <= b

a <= b is an expression. All expressions boil down to a value, which in this case IS LITERALLY, true or false. No need to use more code to do the obvious.

1 Like

I cannot complete the project and I would like some help.

When I test run the code, no error message was reported. However when I press the “Make a Guess” button, the program failed to compare the result and the “Next Round” button is not enabled.

function compareGuesses(humanGuess, computerGuess, target) {
let humanVar = Math.abs(humanGuess - target);
let computerVar = Math.abs(computerGuess - target);
if (humanVar === computerVar) {
return true;
} else if (humanVar > computerVar) {
return false;
} else {
return true;
}
}


I shared my project that I worked with but I have a question regarding if the user chose a number not between 0 to 9 how to break the game or restart it.