Number Guesser

Help, I’m very confused here. I’ve done the number guesser project. It works except that the score and the round don’t change. I’m pretty sure this is because I’ve written =+ instead of +=. However, if I switch those operators round, then I can no longer click the ‘make a guess button’ in the browser. The error in the developer tools states 'unexpected token: ‘+=’. I can’t figure it out, any ideas? Thanks!

Hi @nicolahearn
yes, =+ is an assignment. It assigns a positive value (+1) to the variable humanScore or computerScore.
If you turn it around, you get into trouble because you redeclare your variables each round. Instead of

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

you better write

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

Amazing, thanks. I also noticed I had written advanceRoundNumber instead of currentRoundNumber. All working now :slight_smile:

1 Like