-
-
Save codecademydev/c4e39c136c6f6e6fb374775b46bdcba5 to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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