-
-
Save codecademydev/6ab6b82007d1cdeb36c8ac803700804a 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; | |
// 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