-
-
Save codecademydev/f1c453ac5e24c42faba90be3daa7a344 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: | |
// function generateTarget() { | |
// return Math.floor(Math.random() * 9); | |
// } | |
// function compareGuesses(guess, computerGuess, target) { | |
// const guessDiff = Math.abs(target - guess); | |
// const computerGuessDiff = Math.abs(target - computerGuess); | |
// return guessDiff <= computerGuessDiff; | |
// } | |
// function updateScore(winner) { | |
// if (winner == 'human') { | |
// humanScore += 1; | |
// } else { | |
// computerScore += 1; | |
// } | |
// } | |
// function advanceRound() { | |
// currentRoundNumber += 1; | |
// } | |
// my code here: | |
function generateTarget() { | |
return Math.floor(Math.random() * 9); | |
} | |
function compareGuesses(humanGuess, computerGuess, target) { | |
const humanGuessDiff = Math.abs(humanGuess-target); | |
const computerGuessDiff = Math.abs(computerGuess-target); | |
if (humanGuess > 9) { | |
return alert('Pick a number that is between 0-9!') | |
} else if (humanGuessDiff <= computerGuess) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
function updateScore(winner) { | |
if (winner == 'human') { | |
humanScore++; | |
} else if (winner == 'computer') { | |
computerScore++; | |
} | |
} | |
function advanceRound() { | |
return currentRoundNumber ++; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment