-
-
Save codecademydev/2b0eae4fe672bb6e10766ba53d6243be to your computer and use it in GitHub Desktop.
Codecademy export
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; | |
// The random number: | |
let generateTarget = () => { | |
return Math.floor(Math.random()*9); | |
}; | |
// Compare the guess number between computer, user and target number | |
let compareGuesses = (human, computer, target) =>{ | |
const userG = Math.abs(target-human); | |
const computerG = Math.abs(target-computer); | |
return userG <= computerG; | |
} | |
// Add to the score number to winner | |
const updateScore = winner =>{ | |
if (winner === 'computer'){ | |
computerScore += 1; | |
} else{ | |
humanScore += 1; | |
} | |
} | |
// add to round number after each round | |
const advanceRound = () =>{ | |
currentRoundNumber += 1; | |
}; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am a new programmer. These codes are one part of a project in the Codecademy Web Development course. At first glance, it was a bit tricky to build it because there where several ways to write these codes. However, I tried to pay attention to the importance of controlling the complexity of the program.
I would be highly grateful if you could write your opinion about it.