Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 30, 2021 00:49
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/685cea5c46ee0de1db1a161ab15c5ec4 to your computer and use it in GitHub Desktop.
Save codecademydev/685cea5c46ee0de1db1a161ab15c5ec4 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
// Generate a random number between 0 and 9
const generateTarget = () => Math.floor(Math.random() * 9);
// Function compares guesses
function compareGuesses(user, computer, target) {
const userDif = Math.abs(user - target);
const computerDif = Math.abs(computer - target);
// return true if user won and false if computer won
return (userDif <= computerDif);
} // end of compareGuesses function
// function updates global human or computer score
function updateScore(winner) {
(winner === 'human') ? humanScore += 1 : computerScore += 1;
} // end of updateScore() function
// function increases global currrentRoundNumber each round
const advanceRound = () => currentRoundNumber += 1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment