Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created June 8, 2021 21:10
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/60ae7fe3ae7c5e90a036e209112ba91e to your computer and use it in GitHub Desktop.
Save codecademydev/60ae7fe3ae7c5e90a036e209112ba91e to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
//generates a random secret number
const generateTarget = () => {
let random = Math.floor(Math.random()*10);
return random
}
// determines who won the round
const compareGuesses = (humanNum, computerNum, secretNum) => {
let humanRemain = Math.abs(secretNum - humanNum);
let computerRemain = Math.abs(secretNum - computerNum);
if (humanRemain <= computerRemain) { return true }
else {return false}
}
//updates the score card by one
const updateScore = (winner) => {
switch (winner) {
case 'human' : humanScore = humanscore + 1;
case 'computer' : computerScore = computerScore + 1;
}
}
//updates the round number after each round
const advanceRound = () => {
currentRoundNumber = currentRoundNumber + 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment