Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created November 12, 2020 14:39
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 codecademydev/883aa66f62ad9aee4eac2b3b8392a8a2 to your computer and use it in GitHub Desktop.
Save codecademydev/883aa66f62ad9aee4eac2b3b8392a8a2 to your computer and use it in GitHub Desktop.
Codecademy export
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