-
-
Save codecademydev/9be103e131b6adda3925820c5a7e4683 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: | |
const generateTarget = () => { | |
return Math.floor(Math.random() * 10); | |
}; | |
const getAbsoluteDistance = (num1, num2) => { | |
return Math.abs(num1 - num2); | |
} | |
function compareGuesses(userNum, computerNum, targetNum) { | |
if (userNum < 0 || userNum > 9) { | |
alert('Number out of range!'); | |
return; | |
} | |
if ( | |
getAbsoluteDistance(targetNum, userNum) < getAbsoluteDistance(targetNum, computerNum) || | |
getAbsoluteDistance(targetNum, userNum) === getAbsoluteDistance(targetNum, computerNum) | |
) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
const updateScore = function(winner) { | |
winner === 'human' ? humanScore++ : computerScore++; | |
} | |
const advanceRound = () => { | |
currentRoundNumber++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment