Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 22, 2020 07:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/f1c453ac5e24c42faba90be3daa7a344 to your computer and use it in GitHub Desktop.
Save codecademydev/f1c453ac5e24c42faba90be3daa7a344 to your computer and use it in GitHub Desktop.
Codecademy export
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