-
-
Save codecademydev/d456e9f3c87ba9a28d3cfe6074eed1b9 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let humanScore = 0; | |
let computerScore = 0; | |
let currentRoundNumber = 1; | |
// Write your code below: | |
//step 3 | |
let generateTarget = () => { | |
return Math.floor(Math.random() * 9); | |
}; | |
//step 4 | |
let compareGuesses = (human, computer, target) => { | |
const userG = Math.abs(target - human); | |
const computerG = Math.abs(target - computer); | |
return userG <= computerG; | |
/*if (userG <= computerG) { | |
updateScore('human'); | |
} else { | |
updateScore('computer'); | |
}*/ | |
}; | |
//step 5 | |
let updateScore = winner => { | |
if (winner === 'human') { | |
humanScore += 1; | |
} else if (winner === 'computer') { | |
computerScore += 1; | |
} | |
}; | |
//step 6 | |
function advanceRound() { | |
currentRoundNumber += 1; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mrstosh Your mistake is inside the code block of your function "updateScore". In the condition, that the if statement checks, you wrote
" "winner" === "user" " but because you used quotation marks around "winner", the programm treats that as a string and not as the parameter of the function. So, you just have to leave the quotation around "winner" in both if statement conditions.