Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created April 13, 2022 21:14
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/d599e513f09aff4bfa4e3c7152088f2e to your computer and use it in GitHub Desktop.
Save codecademydev/d599e513f09aff4bfa4e3c7152088f2e to your computer and use it in GitHub Desktop.
Codecademy export
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