Skip to content

Instantly share code, notes, and snippets.

@ZEwela
Created February 11, 2022 17:45
Show Gist options
  • Save ZEwela/e2d5eb35caef6a71086c0440ad401327 to your computer and use it in GitHub Desktop.
Save ZEwela/e2d5eb35caef6a71086c0440ad401327 to your computer and use it in GitHub Desktop.
codecademy project
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
const generateTarget = () => {
return Math.floor(Math.random() * 10);
};
const getAbsoluteDistance = (target, guess) => {
return Math.abs(target - guess);
};
const compareGuesses = (humanGuess, computerGuess, secretTarget) => {
if (humanGuess < 0 || humanGuess > 9) {
alert('Choose between 0 and 9!')
};
let checkHumanGuess = getAbsoluteDistance(secretTarget, humanGuess);
let checkComputerGuess = getAbsoluteDistance(secretTarget, computerGuess);
return checkHumanGuess <= checkComputerGuess ? true : false;
};
const updateScore = winner => {
winner === 'human' ? humanScore ++ : computerScore ++;
};
const advanceRound = () => {
currentRoundNumber ++
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment