-
-
Save codecademydev/253fa0db2c4b96e07931d78f6b5ed022 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 compareGuesses = (humanGuess, computerGuess, targetNum) => { | |
if (humanGuess > 9 || humanGuess < 0) { | |
alert('User is out of range'); | |
} | |
const humanDiff = getAbsoluteDistance(targetNum, humanGuess); | |
const computerDiff = getAbsoluteDistance(targetNum, computerGuess); | |
if (humanDiff <= computerDiff) { | |
return true | |
} else { | |
return false | |
} | |
} | |
const updateScore = winner => { | |
if (winner === 'computer') { | |
computerScore++ | |
} else { | |
humanScore++ | |
} | |
} | |
const advanceRound = () => { | |
currentRoundNumber++ | |
}; | |
const getAbsoluteDistance = (target, guess) => { | |
return Math.abs(target - guess); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment