Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created August 13, 2020 21:34
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/0d69b1dd380b8c76f6cbc31483640d37 to your computer and use it in GitHub Desktop.
Save codecademydev/0d69b1dd380b8c76f6cbc31483640d37 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget=()=>Math.floor(Math.random()*10)
function getAbsoluteDistance(a,b) {
return Math.abs(b-a)
}
function compareGuesses(humanGuess,computerGuess, Target) {
if (humanGuess<0 || humanGuess>9) {window.alert('Number is out of range')}
if (humanGuess===computerGuess)
{return true}
else if (getAbsoluteDistance(computerGuess,Target)>getAbsoluteDistance(humanGuess,Target)) {return true} else {return false}
}
function updateScore(winner) {
if (winner==='human') {humanScore+=1}
else {computerScore+=1}
}
const advanceRound=()=>currentRoundNumber+=1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment