Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created June 14, 2021 16:38
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/591354c2ef8f46163b5fbaa241ab41f5 to your computer and use it in GitHub Desktop.
Save codecademydev/591354c2ef8f46163b5fbaa241ab41f5 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
function generateTarget() {
return Math.floor(Math.random() * 10)
}
function compareGuesses(humanGuess, computerGuess, target) {
const diffHumanGuess = Math.abs(target - humanGuess);
const diffComputerGuess = Math.abs(target - computerGuess);
if (diffHumanGuess <= diffComputerGuess) {
return true;
} else {
return false;
}
}
function updateScore(winner) {
if (winner == 'human') humanScore += 1;
else computerScore += 1;
}
function advanceRound() {
currentRoundNumber += 1;
}
@amcglen
Copy link

amcglen commented Jun 15, 2021

Great work!

You can make your code a little more succinct by using the increment operator to increase the relevant variables by one for the functions updateScore() and advanceRound():

function advanceRound() {
currentRoundNumber++;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment