Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created October 14, 2020 14:21
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/f685f5e009f897cc9c8610533d299ba1 to your computer and use it in GitHub Desktop.
Save codecademydev/f685f5e009f897cc9c8610533d299ba1 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
// Step 3
const generateTarget = () => {
generateTarget = Math.floor(Math.random() *9)
}
// Step 4
const compareGuess = (humanGuess , computerGuess, targetNumber) => {
let humanDifference = Math.abs(humanGuess - targetNumber);
let computerDifference = Math.abs(computerGuess - targetNumber);
if (humanDifference >= computerDifference) {
return true;
} else if (humanDifference < computerDifference) {
return false;
} else {
return 'Error this game be broken.';
}
};
// Step 5
const updateScore = winner => {
if (winner === 'human') {
humanScore + 1;
} else if (winner === 'computer') {
computerScore + 1;
};
}
// Step 6
const advanceRound = () => currentRoundNumber++;
updateScore('human');
console.log(humanScore); // To confirm that this value increased by 1
updateScore('computer');
console.log(computerScore); // To confirm that this value increased by 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment