Javascript Number Guesser Project

Hello :),

I am currently working on a number guesser and im confused on why the ‘<=’ operator is used in the situation.

Here’s my code:

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 target = generateTarget;
    const humanDifference = Math.abs(humanGuess - targetGuess);
    const computerDifference = Math.abs(target - computerGuess);
    return humanDifference <= computerDifference;

Im unsure of the use of the ‘<=’ in the return section. What does it do? I’ve only ever known that function to be used when numbers are involved, but in this instance, what would the ‘returned’ factor be and why would it be that.

Sorry if im getting confused for no reason :stuck_out_tongue:


you mean comparison operator? <= is a comparison operator.

the purpose of return hasn’t changed, we hand back/return the result of the comparison to the caller

a comparison is either true or false, so essentially, compareGuesses function returns a boolean value

1 Like

HI there,

Sorry to keep asking, im just still not sure on the purpose of the comparison operator (sorry i didnt know the name before :confused:).

I noticed that the console said false when I tested it with a console.log, but why exactly is it saying false?

Does it compare the humanDifference with the computerDifference and say true if the humanDifference is less than or equal to the computerDifference?


exactly, in which case the user wins the game.

you seem to understand :slight_smile:

1 Like