Skip to content

Instantly share code, notes, and snippets.

@thesnitchie
Created July 22, 2021 18:07
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 thesnitchie/e044b1183568573ccefd691a0e152e27 to your computer and use it in GitHub Desktop.
Save thesnitchie/e044b1183568573ccefd691a0e152e27 to your computer and use it in GitHub Desktop.
Number Guesser Project
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.
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