-
-
Save thesnitchie/e044b1183568573ccefd691a0e152e27 to your computer and use it in GitHub Desktop.
Number Guesser Project
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
This is my current solution for the Number Guesser project. | |
My code seems to be a bit more complicated than the solution given by Codecademy, but I'm proud of it. | |
Not bad for a first attempt. | |
I will update later with the extension challenges. |
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 = () => { | |
return Math.floor(Math.random() * 10) | |
}; | |
const compareGuesses = (userGuess,computerGuess,targetNumber) => { | |
if (Math.abs(targetNumber - userGuess) <= Math.abs(targetNumber - computerGuess)) { | |
return true | |
} else { | |
return false | |
}; | |
} | |
const updateScore = (winner) => { | |
if (winner === 'human') { | |
humanScore += 1 | |
} else { | |
computerScore +=1 | |
} | |
} | |
const advanceRound = () => { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment