Created
January 18, 2022 23:46
-
-
Save alexanderverheijden/b24427c61f1fa85693639230f35f5e69 to your computer and use it in GitHub Desktop.
Practice project from codecademy (18-1-2022)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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