-
-
Save codecademydev/91b8bcb389ff5369221fe0b882494860 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: | |
// Generate random number between 0 - 9 | |
const generateTarget = () => Math.floor(Math.random() * 10); | |
// Compare user and cpu guesses with target | |
const compareGuesses = (user, cpu, secret) => { | |
if( user < 0 || user > 9){ | |
alert('Please pick a number between 0 and 9') | |
}; | |
let userGuess = Math.abs(secret - user); | |
let cpuGuess = Math.abs(secret - cpu); | |
// True = user wins , False = cpu wins Does not matter if it goes over | |
return user === cpu ? true : | |
userGuess <= cpuGuess ? true : | |
false | |
}; | |
// update score fn | |
const updateScore = (str) => { | |
str === 'human' ? humanScore++ : computerScore++; | |
}; | |
// go to next round fn | |
const advanceRound = () => currentRoundNumber++; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment