-
-
Save codecademydev/883aa66f62ad9aee4eac2b3b8392a8a2 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; | |
// Write your code below: | |
const generateTarget = () => { | |
var targetNumber = Math.floor(Math.random() * 10); | |
return targetNumber; | |
} | |
const compareGuesses = (humanGuess, computerGuess, targetGuess) => { | |
const humanTarget = (humanGuess, targetGuess) => { //beregner den numeriske afstand til "targetnumber" for human. | |
if (humanGuess > targetGuess) { | |
humanTarget = humanGuess - targetGuess; | |
} | |
else { | |
humanTarget = targetGuess - humanGuess; | |
} | |
} | |
const computerTarget = (computerGuess, targetGuess) => { //bergner den numeriske afstand til "targetnumber" for computeren. | |
if (computerGuess > targetGuess) { | |
computerTarget = computerGuess - targetGuess; | |
} | |
else { | |
computerTarget = targetGuess - computerGuess; | |
} | |
} | |
if (humanGuess === computerGuess) { // hvis human og computer gætter ens er der tie = point til human. | |
return true; | |
} | |
else if (humanTarget < computerTarget) { //hvis human har mindst afstand til "targetnumber" vinder human. | |
return true; | |
} | |
else { //hvis computeren har mindst afstand til target vinder computeren. | |
return false; | |
} | |
} | |
let updateScore = winnerString => { | |
if (winnerString === "human") { | |
humanScore += 1; | |
} | |
else if (winnerString === "computer") { | |
computerScore += 1; | |
} | |
} | |
function advanceRound() { | |
currentRoundNumber += 1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment