-
-
Save codecademydev/470b9a3862370a602bdcb118f4ae295e 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: | |
// Generates random 0-9 number | |
const generateTarget = () => Math.floor(Math.random() * 10); | |
// Calculates guess variances | |
const getAbsoluteDistance = (num1,num2) => num1 - num2; | |
// Compares guesses to target and issues alert for guess range | |
function compareGuesses(human,cpu,target){ | |
let humanPoints = getAbsoluteDistance(target - human); | |
let cpuPoints = getAbsoluteDistance(target - cpu); | |
// Range alert | |
if (human <= 9) { | |
alert('Number is out of range. It’s not possible to set a number outside this range with the + and = buttons') | |
} | |
// returns true for human winner | |
if (humanPoints <= cpuPoints){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
// Adds to winner's score | |
function updateScore(winner) { | |
if (winner === 'human') { | |
humanScore += 1; | |
} else { | |
computerScore += 1; | |
} | |
} | |
// Advances number of rounds | |
const advanceRound = () => currentRoundNumber += 1; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment