Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 14, 2021 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/ac89c2b365ed3ab938a73ac5cf2cdd25 to your computer and use it in GitHub Desktop.
Save codecademydev/ac89c2b365ed3ab938a73ac5cf2cdd25 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
function generateTarget() {
return Math.floor(Math.random() * 9);
}
function compareGuesses(user, computer, target) {
let userValue = Math.abs(target - user);
let computerValue = Math.abs(target - computer);
if (userValue < computerValue) {
return true;
} else if (userValue > computerValue) {
return false;
} else {
return true;
}
}
function updateScore(winner) {
if (winner === 'human') {
humanScore += 1;
} else if (winner === 'computer') {
computerScore += 1;
} else {
return 'ERROR!'
}
}
function advanceRound() {
currentRoundNumber += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment