Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created Nov 21, 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 = () => {
return Math.floor(Math.random() * 10);
}
const compareGuesses = (humanGuess, computerGuess, targetGuess) => {
if (Math.abs((humanGuess - targetGuess) < (computerGuess - targetGuess)) {
return true;
} else if (Math.abs((humanGuess - targetGuess) > (computerGuess - targetGuess)){
return false;
} else {
return true;
}
};
const updateScore = winner => {
if (comapareGuesses === true) {
return humanScore + 1;
} else
return computerScore + 1;
}
const advanceRound = () => currentRoundNumber ++
updateScore('human');
console.log(humanScore);
updateScore('computer');
console.log(computerScore);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment