Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created March 4, 2021 20:35
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/6ab6b82007d1cdeb36c8ac803700804a to your computer and use it in GitHub Desktop.
Save codecademydev/6ab6b82007d1cdeb36c8ac803700804a to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
// Step 3
const generateTarget = () => {
return Math.floor(Math.random()*10);
}
//extension Step 8.1
const getAbsolutDistance = (guess, target) => {
return Math.abs(target-guess);
}
// Step 4
const compareGuesses = (human, computer, target) => {
//extension Step 8.2
if(human > 10 || human < 0){
alert('Problem');
}
//extension 8.1 function call
const humanDifference = getAbsolutDistance(human, target);
const computerDifference = getAbsolutDistance(computer, target);
//if tied player win
if(humanDifference === computerDifference){
return true;
} else if(humanDifference < computerDifference){
return true;
} else if(humanDifference > computerDifference){
return false;
}
}
//Step 5
const updateScore = (winner) => {
if (winner==='human'){
humanScore += 1;
}else if (winner==='computer'){
computerScore += 1;
}
}
//Step 6
const advanceRound = () =>{
currentRoundNumber += 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment