Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created May 1, 2020 02:55
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/c4e39c136c6f6e6fb374775b46bdcba5 to your computer and use it in GitHub Desktop.
Save codecademydev/c4e39c136c6f6e6fb374775b46bdcba5 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// -------------------------------------------------------------
function generateTarget(){
return Math.floor(Math.random() * 10)
};
// -------------------------------------------------------------
// ---------------------------------------------------
function getAbsoluteDistance(num1,num2){
return Math.abs(num1 - num2);
}
// --------------------------------------------------------------
function compareGuesses(currentHumanGuess, computerGuess, target) {
// body...
if(currentHumanGuess < 0 || currentHumanGuess > 9){
alert("The number you entred is not a valid");
return;
}else{
let abshum = getAbsoluteDistance(target,currentHumanGuess);
// console.log(abshum)
// ------------------------------------------------------
let abscom = getAbsoluteDistance(target,computerGuess);
// console.log(abscom)
// ------------------------------------------------------
if ( abshum < abscom ) {
return true;
} else {
return false;
};
}
}
// ------------------------------------------------
function updateScore(winner) {
// body...
if (winner === "human") {
humanScore += 1;
}
else if (winner === "computer") {
computerScore += 1;
} else {
computerScore += 0;
}
}
// --------------------------------------------------
function advanceRound() {
// body...
return currentRoundNumber += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment