Skip to content

Instantly share code, notes, and snippets.

@alexanderverheijden
Created January 18, 2022 23:46
Show Gist options
  • Save alexanderverheijden/b24427c61f1fa85693639230f35f5e69 to your computer and use it in GitHub Desktop.
Save alexanderverheijden/b24427c61f1fa85693639230f35f5e69 to your computer and use it in GitHub Desktop.
Practice project from codecademy (18-1-2022)
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);
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment