-
-
Save codecademydev/685cea5c46ee0de1db1a161ab15c5ec4 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: | |
// 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