Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 26, 2020 16:44
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/1be259cb70163152d336f86c5e29d6d5 to your computer and use it in GitHub Desktop.
Save codecademydev/1be259cb70163152d336f86c5e29d6d5 to your computer and use it in GitHub Desktop.
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 = (human, computer, target) => {
if (human<=9) {
/*if ((human === target) || (human === computer)) {
return true;
} else if ((human !== target) && (computer === target)) {
return false;
} else if ((human !== target) && (computer !== target)) {
humanAbs = Math.abs(human-target);
computerAbs = Math.abs(computer-target);
if (humanAbs <= computerAbs) {
return true
} else {return false;};
};*/
humanAbs = Math.abs(human-target);
computerAbs = Math.abs(computer-target);
return humanAbs - computerAbs;
} else alert('Number above 9');
};
const updateScore = (winner) => {
if (winner==='human') {
//humanScore += 1;
humanScore++;
} else if (winner==='computer') {
//computerScore +=1;
computerScore++;
}
};
const advanceRound = () =>{
//currentRoundNumber += 1;
currentRoundNumber++;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment