Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 27, 2020 06:06
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/fad7fbb8ed94ce13260db31aa6efd202 to your computer and use it in GitHub Desktop.
Save codecademydev/fad7fbb8ed94ce13260db31aa6efd202 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
// Step 03
const generateTarget = () => {
return Math.floor(Math.random() * 10);
}
// Step 04
const compareGuesses = (humanGuess, computerGuess, targetNumber) => {
let humanDistance = Math.abs((humanGuess - targetNumber));
let computerDistance = Math.abs((computerGuess - targetNumber));
if (humanDistance === computerDistance) {
return true;
} else if (humanDistance < computerDistance) {
return true;
} else {
return false;
}
};
// Step 05
const updateScore = winner => {
if (winner === 'human') {
humanScore += 1;
} else {
computerScore += 1;
}
};
// Step 06
const advanceRound = () => {
currentRoundNumber += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment