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 compareGuesses = (humanGuess, computerGuess, targetNum) => {
if (humanGuess > 9 || humanGuess < 0) {
alert('User is out of range');
}
const humanDiff = getAbsoluteDistance(targetNum, humanGuess);
const computerDiff = getAbsoluteDistance(targetNum, computerGuess);
if (humanDiff <= computerDiff) {
return true
} else {
return false
}
}
const updateScore = winner => {
if (winner === 'computer') {
computerScore++
} else {
humanScore++
}
}
const advanceRound = () => {
currentRoundNumber++
};
const getAbsoluteDistance = (target, guess) => {
return Math.abs(target - guess);
};
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.