-
-
Save codecademydev/f2eb490a83cabba42080cbaccaff32d0 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; | |
const generateTarget = () => Math.floor(Math.random() * 10); | |
const secretNumber = generateTarget(); | |
const getAbsoluteDistance = (number1, number2) => Math.abs((number1 - number2)); | |
function compareGuesses(humanGuess, computerGuess, secretNumber) { | |
const humanProximity = getAbsoluteDistance(humanGuess, secretNumber); | |
const computerProximity = getAbsoluteDistance(computerGuess, secretNumber); | |
if (humanGuess < 0 || humanGuess > 9) { | |
window.alert ('The number is out of range. Range = [0, 9].'); | |
return false; | |
} else if (humanGuess > 0 && humanGuess <= 9) { | |
if (humanProximity < computerProximity || humanProximity === computerProximity) { | |
return true; | |
} else if (humanProximity > computerProximity) { | |
return false; | |
} | |
} | |
}; | |
function updateScore(winner) { | |
if (winner === 'human') { | |
humanScore++; | |
} else if (winner === 'computer') { | |
computerScore++; | |
} | |
}; | |
const advanceRound = () => currentRoundNumber++; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment