-
-
Save codecademydev/d599e513f09aff4bfa4e3c7152088f2e 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: | |
//Return a random integer between 0 and 9 | |
const generateTarget = () => Math.floor(Math.random() * 9); | |
//Determines which player (human or computer) wins based on which guess is closest to the target | |
const compareGuesses = (humanGuess, computerGuess, target) => Math.abs(target - humanGuess) <= Math.abs(target - computerGuess) ? true : false; | |
//Increases the score variable (humanScore or computerScore) by 1 depending on the winner | |
const updateScore = winner => winner === 'human' ? humanScore++ : computerScore++; | |
//Increase the value of currentRoundNumber by 1 | |
const advanceRound = () => currentRoundNumber++; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment