Created
October 12, 2021 23:46
-
-
Save jurgden/d3752d5f0615f32aea6d9caad0dce7cb to your computer and use it in GitHub Desktop.
Number Guesser Challenge Project @jurgdenFutures
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 = 0; | |
// Beginning of the code. 1st function. | |
const generateTarget = () => { | |
return Math.floor(Math.random() * 10); | |
} | |
// Xtra funtion for human : cpu comparison. | |
// .... I really tried hard for a couple of hours haha :C RIP | |
// 2nd function. | |
const compareGuesses = (human, computer, secret) => { | |
let dist1 = Math.abs(secret - human) | |
let dist2 = Math.abs(secret - computer) | |
return dist1 <= dist2; | |
} | |
compareGuesses(); | |
// Finished | |
// 3rd function. | |
const updateScore = (winner) => { | |
if (winner === 'human') { | |
let humPts = humanScore += 1; | |
return humPts; | |
} else if (winner === 'computer') { | |
let comPts = computerScore += 1; | |
return comPts; | |
} | |
} | |
updateScore(); | |
// Finished | |
// 4th function. | |
const advanceRound = () => { | |
let newRound = currentRoundNumber ++; | |
return newRound; | |
} | |
advanceRound(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment