-
-
Save codecademydev/60ae7fe3ae7c5e90a036e209112ba91e 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: | |
//generates a random secret number | |
const generateTarget = () => { | |
let random = Math.floor(Math.random()*10); | |
return random | |
} | |
// determines who won the round | |
const compareGuesses = (humanNum, computerNum, secretNum) => { | |
let humanRemain = Math.abs(secretNum - humanNum); | |
let computerRemain = Math.abs(secretNum - computerNum); | |
if (humanRemain <= computerRemain) { return true } | |
else {return false} | |
} | |
//updates the score card by one | |
const updateScore = (winner) => { | |
switch (winner) { | |
case 'human' : humanScore = humanscore + 1; | |
case 'computer' : computerScore = computerScore + 1; | |
} | |
} | |
//updates the round number after each round | |
const advanceRound = () => { | |
currentRoundNumber = currentRoundNumber + 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment