-
-
Save codecademydev/020545428d33658e19051afb53bcc383 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: | |
const generateTarget = () => Math.floor(Math.random()*10); | |
const getAbsoluteDistance = (guess, target) => Math.abs(guess-target); | |
const compareGuesses = (userGuess, computerGuess, secretTarget) => { | |
if (userGuess < 0 || userGuess > 9) { | |
alert('Please choose a number between 0 and 9'); | |
} | |
let userDistance = getAbsoluteDistance(userGuess, secretTarget); | |
let computerDistance = getAbsoluteDistance(computerGuess, secretTarget); | |
if (userDistance <= computerDistance) { | |
return true; | |
} else if (userDistance > computerDistance) { | |
return false; | |
} else { | |
console.log ('Error!'); | |
} | |
} | |
const updateScore = winner => { | |
if (winner==='human') { | |
humanScore++; | |
} else { | |
computerScore++; | |
} | |
} | |
const advanceRound = () => currentRoundNumber++; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment