Skip to content

Instantly share code, notes, and snippets.

@aldojack
Created April 6, 2021 16:37
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 aldojack/ffee6627bce704380a4e9c5727b7c5e7 to your computer and use it in GitHub Desktop.
Save aldojack/ffee6627bce704380a4e9c5727b7c5e7 to your computer and use it in GitHub Desktop.
NumberGuesser/Codecademy/js
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