-
-
Save codecademydev/81ec160072ab72866c998b090301a666 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; | |
function generateTarget() { | |
return Math.floor(Math.random()*10); | |
} | |
function compareGuesses( humanGuess , computerGuess , secretGuess = generateTarget()) { | |
if ( Math.abs(humanGuess-secretGuess) <= Math.abs(computerGuess-secretGuess)){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function updateScore(winner){ | |
if (winner !== 'human' && winner !=='computer' ){ | |
console.log('Failure to updateScore because parameter is invalid'); | |
return ; | |
} | |
if (winner === 'human'){ | |
humanScore++; | |
return ; | |
} else if (winner === 'computer'){ | |
computerScore++; | |
return ; | |
} | |
} | |
function advanceRound(){ | |
currentRoundNumber++; | |
return ; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment