Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 23, 2020 19:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/0b2421fdd60fef03264d8ac7da738b67 to your computer and use it in GitHub Desktop.
Save codecademydev/0b2421fdd60fef03264d8ac7da738b67 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// this will return a number from 0 to 9
const generateTarget = () => {
return Math.floor(Math.random() * 10);
};
//This will determine the winner
const compareGuesses = (human, computer, target) => {
if(human > 9 || human < 0) {
alert('Enter a number between 0 and 9');
}
const humanDifference = Math.abs(human - target);
const computerDifference = Math.abs(computer - target);
if(humanDifference === computerDifference) {
return true;
} else if(humanDifference < computerDifference) {
return true;
} else if(humanDifference > computerDifference) {
return false;
}
};
//This will change the score
const updateScore = winner => {
if(winner === 'human') {
humanScore += 1;
} else {
computerScore += 1;
}
};
const advanceRound = () => {
(currentRoundNumber += 1);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment