Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 17, 2020 13:06
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save codecademydev/e308cc7793634a3dc3d7cc4bf7cc2ea3 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
// 3. generates the secret target number, a random int 0-9.
const generateTarget = () => Math.floor(Math.random()*10);
// 7a. returns the distance between 2 numbers.
const getAbsoluteDistance = (a, b) => Math.abs(a - b);
// 4. returns true if user is closer to target, or tie; returns false if computer is closer to target. alerts if guess is out of range.
const compareGuesses = (humansGuess, computersGuess, targetNum) => {
if ((humansGuess < 0) || (humansGuess > 9)){
window.alert('You\'ve lost for being a smartass! Next time, stay in the safe zone of 0 through 9!');
} else if ((getAbsoluteDistance(humansGuess, targetNum)) <= (getAbsoluteDistance(computersGuess, targetNum))){
return true;
} else {
return false;
};
};
// 5. announces winner and updates score.
const updateScore = winner => {
if (winner === 'human') {
humanScore ++;
} else {
computerScore ++;
};
};
// 6. activates the 'Next Round' botton.
const advanceRound = () => currentRoundNumber ++;
@sadiqsd1
Copy link

sadiqsd1 commented Aug 7, 2020

well done your code was super easy to understand and that line smartass so funny man all the best

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment