Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created December 30, 2021 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/14d85dc8acde5adcb76e426e1c36eae7 to your computer and use it in GitHub Desktop.
Save codecademydev/14d85dc8acde5adcb76e426e1c36eae7 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
function generateTarget() {
return Math.floor(Math.random() * 10)
}
function compareGuesses(human, computer, secret) {
if ((human > 9) || (human < 0)) {
alert('Guesses can only be between 0 and 9')
return false
}
if (human == computer) return true
if (getAbsoluteDistance(human, secret) < getAbsoluteDistance(computer, secret)) return true
else return false
}
function getAbsoluteDistance(a, b) {
return Math.abs(a - b)
}
function updateScore(winner) {
if (winner === 'human') humanScore++
else computerScore++
}
function advanceRound() {
currentRoundNumber++
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment