-
-
Save codecademydev/2ecb55ce7ccc9c9b8272d8cfba39d1d8 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 = () => Math.floor(Math.random()*10); | |
//Step 8.1 function for distance calculation | |
const getAbsolutDistance = (guess, target) => Math.abs(target-guess); | |
//Step 4 | |
const compareGuesses = (human, computer, target) => { | |
//Step 8.2 alert box | |
if(human > 10 || human < 0){ | |
alert('Problem detected, you are out of range!'); | |
} | |
//Step 4 winner calculation | |
if(getAbsolutDistance(human, target) <= getAbsolutDistance(computer, target)){ | |
return true; | |
} else { | |
return false; | |
} | |
} | |
//Step 5 | |
const updateScore = (winner) => { | |
if (winner==='human'){ | |
humanScore++; | |
}else { | |
computerScore++; | |
} | |
} | |
//Step 6 | |
const advanceRound = () => currentRoundNumber++; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment