Skip to content

Instantly share code, notes, and snippets.

@codecademydev

codecademydev/script.js Secret

Created Sep 14, 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) => {
return Math.abs(guess - target);
}
const compareGuesses = (userGuess, computerGuess, secretTarget) => {
if (userGuess >= 0 && userGuess <= 9) {
const userDifference = getAbsoluteDistance(userGuess, secretTarget);
const computerDifference = getAbsoluteDistance(computerGuess, secretTarget);
return userDifference <= computerDifference;
}
else {
alert('Alert! Invalid input. Enter number between 0 and 9');
}
}
const updateScore = (winner) => {
switch (winner) {
case 'human':
humanScore += 1;
break;
case 'computer' :
computerScore += 1;
}
}
const advanceRound = () => currentRoundNumber += 1;
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.