Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 11, 2020 14:28
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/9af4ae8dbe5e3ef45d5524d63eb7acc9 to your computer and use it in GitHub Desktop.
Save codecademydev/9af4ae8dbe5e3ef45d5524d63eb7acc9 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 3
const generateTarget = () => {
return Math.floor(Math.random() * 10);
};
// Step 7
const getAbsoluteDistance = (input, target) => Math.abs(target - input);
// Step 4
const compareGuesses = (human, computer, target) => {
if (human < 0 || human > 9) {
window.alert('Please only enter number between 0 and 9!')
};
const humanGuess = getAbsoluteDistance(human, target);
const computerGuess = getAbsoluteDistance(computer, target);
if (humanGuess === computerGuess) {
return true;
} else if (humanGuess > computerGuess) {
return false;
} else {
return true;
};
// ternary statement refactor doesn't work?!
// humanGuess <= computerGuess ? true : false;
};
// Step 5
const updateScore = winner => {
if (winner === 'human') {
humanScore += 1;
} else {
computerScore += 1;
}
}
// Step 6
const advanceRound = () => {
currentRoundNumber += 1;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment