Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created January 18, 2022 23:24
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/07400b19a7a5f1a8ff66be1366aa7fa8 to your computer and use it in GitHub Desktop.
Save codecademydev/07400b19a7a5f1a8ff66be1366aa7fa8 to your computer and use it in GitHub Desktop.
Codecademy export
let humanScore = 0;
let computerScore = 0;
let currentRoundNumber = 1;
// Write your code below:
const generateTarget = () => {
x = Math.floor(Math.random() * 10);
return x;
};
const compareGuesses = (humanG, computerG, target) => {
const humanDif = Math.abs(humanG - target);
const computerDif = Math.abs(computerG - target);
if (humanDif <= computerDif) {
return true;
};
return false;
};
const updateScore = (winner) => {
if (winner === 'human') {
humanScore++;
} else {
computerscore++;
};
};
const advanceRound = () => {
currentRoundNumber++;
};
/* let secretNum = generateTarget();
console.log(secretNum);
console.log(compareGuesses(1, 2, secretNum));
advanceRound();
console.log(currentRoundNumber);
updateScore('human');
console.log(humanScore);
console.log(computerScore);
*/
@alexanderverheijden
Copy link

This is my practice code.

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