{"size": 1041, "ext": "js", "max_stars_repo_path": "spec_1/GuessTheNumber.js", "max_stars_repo_name": "mKleinCreative/benchmark-goals", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "spec_1/GuessTheNumber.js", "max_issues_repo_name": "mKleinCreative/benchmark-goals", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "spec_1/GuessTheNumber.js", "max_forks_repo_name": "mKleinCreative/benchmark-goals", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.2777777778, "max_line_length": 84, "alphanum_fraction": 0.5869356388}
import readline from 'readline-sync'

const answer = Math.floor(Math.random() * 100) + 1
var count = 10

const exit = 'exit'


const isValidGuess = (input) => {
  return parseInt(input) === true || (parseInt(input) < 100 && parseInt(input) > 0 )
}

const getInput = () => {
  let guess
  do {
    guess = readline.question( 'A number between 1 and 100 please: ' )
    if (guess === exit) {
      return guess
    }
  } while(!isValidGuess(guess))
  return parseInt(guess)
}

const checkForWin = (guessInput) => {
  if ( guessInput === answer ) {
    console.log('You Win!')
    exit
  } else {
    let difference = answer - guessInput
    if ( difference < 0 ) {
      console.log( 'Your guess is too high!' )
    } else {
      console.log( 'Your guess is too low!' )
    }
  }
}

const guessTheNumber = () => {
  let guessInput = getInput()
  if ( guessInput === exit ){
    count - 10
  } else {
    checkForWin( guessInput )
  }
}
do{
  guessTheNumber()
  count--
}
while (count > 0 && getInput !== exit)
// {
//   guessTheNumber()
// }
