-
-
Save codecademydev/0218daf060eb55eef89abb4ad4414e39 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 = () => { | |
return Math.floor(Math.random()*10); | |
}; | |
const compareGuesses = (humanGuess, compGuess, targetNumber) => { | |
if (humanGuess < 0 || humanGuess > 9) { | |
alert('Your number is out of range. Please enter a number between 0 and 9!'); | |
} else { | |
const humanDifference = humanGuess - targetNumber; | |
const compDifference = compGuess - targetNumber; | |
return Math.abs(humanDifference) > Math.abs(compDifference) | |
} | |
} | |
const updateScore = winner => { | |
if (compareGuesses === false) { | |
winner === 'computer'; | |
computerScore++; | |
} else { | |
humanScore++; | |
} | |
} | |
const advanceRound = () => currentRoundNumber++; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment