Created
February 11, 2022 17:45
-
-
Save ZEwela/e2d5eb35caef6a71086c0440ad401327 to your computer and use it in GitHub Desktop.
codecademy project
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 = () => { | |
return Math.floor(Math.random() * 10); | |
}; | |
const getAbsoluteDistance = (target, guess) => { | |
return Math.abs(target - guess); | |
}; | |
const compareGuesses = (humanGuess, computerGuess, secretTarget) => { | |
if (humanGuess < 0 || humanGuess > 9) { | |
alert('Choose between 0 and 9!') | |
}; | |
let checkHumanGuess = getAbsoluteDistance(secretTarget, humanGuess); | |
let checkComputerGuess = getAbsoluteDistance(secretTarget, computerGuess); | |
return checkHumanGuess <= checkComputerGuess ? true : false; | |
}; | |
const updateScore = winner => { | |
winner === 'human' ? humanScore ++ : computerScore ++; | |
}; | |
const advanceRound = () => { | |
currentRoundNumber ++ | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment