-
-
Save codecademydev/682eadb94ca450e4ca972e166b4158df 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; | |
// The random number: | |
let generateTarget = () => { | |
return Math.floor(Math.random()*9); | |
}; | |
// Compare the guess number between computer, user and target number | |
let compareGuesses = (human, computer, target) =>{ | |
const userG = Math.abs(target-human); | |
const computerG = Math.abs(target-computer); | |
return userG <= computerG; | |
} | |
// Add to the score number to winner | |
const updateScore = winner =>{ | |
if (winner === 'computer'){ | |
computerScore += 1; | |
} else{ | |
humanScore += 1; | |
} | |
} | |
// add to round number after each round | |
const advanceRound = () =>{ | |
currentRoundNumber += 1; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment