Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 10, 2020 22:26
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/f2eb490a83cabba42080cbaccaff32d0 to your computer and use it in GitHub Desktop.
Save codecademydev/f2eb490a83cabba42080cbaccaff32d0 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
const generateTarget = () => Math.floor(Math.random() * 10);
const secretNumber = generateTarget();
const getAbsoluteDistance = (number1, number2) => Math.abs((number1 - number2));
function compareGuesses(humanGuess, computerGuess, secretNumber) {
const humanProximity = getAbsoluteDistance(humanGuess, secretNumber);
const computerProximity = getAbsoluteDistance(computerGuess, secretNumber);
if (humanGuess < 0 || humanGuess > 9) {
window.alert ('The number is out of range. Range = [0, 9].');
return false;
} else if (humanGuess > 0 && humanGuess <= 9) {
if (humanProximity < computerProximity || humanProximity === computerProximity) {
return true;
} else if (humanProximity > computerProximity) {
return false;
}
}
};
function updateScore(winner) {
if (winner === 'human') {
humanScore++;
} else if (winner === 'computer') {
computerScore++;
}
};
const advanceRound = () => currentRoundNumber++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment