Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/script.js Secret

Created Sep 17, 2020
Embed
What would you like to do?
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget = () => Math.floor(Math.random()*10);
const getAbsoluteDistance = (guess, target) => Math.abs(guess-target);
const compareGuesses = (userGuess, computerGuess, secretTarget) => {
if (userGuess < 0 || userGuess > 9) {
alert('Please choose a number between 0 and 9');
}
let userDistance = getAbsoluteDistance(userGuess, secretTarget);
let computerDistance = getAbsoluteDistance(computerGuess, secretTarget);
if (userDistance <= computerDistance) {
return true;
} else if (userDistance > computerDistance) {
return false;
} else {
console.log ('Error!');
}
}
const updateScore = winner => {
if (winner==='human') {
humanScore++;
} else {
computerScore++;
}
}
const advanceRound = () => currentRoundNumber++;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.