Number Guesser / Need Help

Hello,

I’m having some trouble with the Number Guesser project and just wanted some input. Please be aware I’m very new to JavaScript and actually still don’t feel like I have much of grasp on the fundamentals. So, my approach to this could be very wrong. But hey, gotta learn somehow right?

Here’s my code:

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

// Write your code below:

//Generates the target number that both user and computer must guess - whoever is closest is declared the winner.
const generateTarget = (number) => {
(Math.floor(Math.random() * 10));
return number;
}

const compareGuesses = (humanGuess, computerGuess, targetNumber) => {
humanGuess = x; //changable
computerGuess = (Math.floor(Math.random() * 10));
targetNumber = generateTarget;

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

const updateScore = (winner) => {

if (compareGuesses === true) {
((winner = ‘human’) && (humanScore + 1))
} else {
((winner = ‘computer’) && (computerScore + 1))
}
};

const advanceRound = () => {
if compareGuesses === (true || false) {
(currentRoundNumber + 1)
}
};

I haven’t tried to print anything to the console yet because I’m getting the following error when I run the code:

/home/ccuser/workspace/independent-practice-js-number-guesser/script.js:38
if compareGuesses === (true || false) {
^^^^^^^^^^^^^^

SyntaxError: Unexpected identifier
at wrapSafe (internal/modules/cjs/loader.js:1001:16)
at Module._compile (internal/modules/cjs/loader.js:1049:27)
at Object.Module._extensions…js (internal/modules/cjs/loader.js:1114:10)
at Module.load (internal/modules/cjs/loader.js:950:32)
at Function.Module._load (internal/modules/cjs/loader.js:790:12)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
at internal/main/run_main_module.js:17:47

it says Unexpected Identifier but from my understanding I’ve defined compareGuesses…

Any help at all would be appreciated!
Thanks!

That is not the correct syntax for an if statement. Also, (true || false) will always be true. Can you explain, why?

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