Created
April 6, 2021 16:37
-
-
Save aldojack/ffee6627bce704380a4e9c5727b7c5e7 to your computer and use it in GitHub Desktop.
NumberGuesser/Codecademy/js
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 = () => { | |
const targetNum = Math.floor(Math.random() * 10); | |
return targetNum; | |
} | |
const compareGuesses = (humanGuess,computerGuess,target) => { | |
return getAbsoluteDistance(humanGuess, target) <= getAbsoluteDistance(computerGuess, target) ? true : false; | |
} | |
const getAbsoluteDistance = (guess,target) => { | |
return Math.abs(guess - target); | |
} | |
const updateScore = winner => { | |
if (winner.toLowerCase() === 'human'){ | |
humanScore++; | |
} | |
else computerScore++; | |
} | |
const advanceRound = () => currentRoundNumber++; | |
// This was from the game.js to get the alert to work, only issue is the program still runs after the alert prompts | |
// guessButton.addEventListener('click', () => { | |
// // Generate the target value | |
// target = generateTarget(); | |
// // Retrieve the player's guess | |
// const currentHumanGuess = humanGuessInput.value; | |
// if ((currentHumanGuess < 0) || (currentHumanGuess >9)){ | |
// window.alert('Please enter a value between 0 and 9'); | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment