js/app.js
// create random number for question 6
create random number for question 6
create random number for question 6
function questionSix() {
  var myMin = 1;
  var myMax = 20;
  var randomNum = Math.random();
  var randomNumber = (Math.floor(randomNum * (myMax - myMin + 1)) + myMin);
  console.log(randomNumber);
  var numberGuess;
  var guesses = 0;
  while (guesses < 4) {
    numberGuess = prompt('Guess a number between 1 and 20. Hint: keep it to integers');
    console.log(numberGuess);
    if (numberGuess > randomNumber) {
      alert('Try something a little lower');
      console.log('Try something a little lower');
    } else if (numberGuess < randomNumber) {
      alert('Try something a little higher');
      console.log('Try something a little higher');
    } guesses++;
    console.log(guesses);
    if (guesses === 4) {
      alert('Sorry, you are out of guesses');
      console.log('Sorry, you are out of guesses');
    } else if (numberGuess == randomNumber) {
      alert('Nice, you guessed correctly');
      console.log('Nice, you guessed correctly');
      correctGuesses = (correctGuesses + 1);
      break;
    } else {
      alert('Why don\'t you give it another shot. You have ' + (4 - guesses) + ' left');
    }
  }
}
function questionSix ( ) { var myMin = 1 ; var myMax = 20 ; var randomNum = Math . random ( ) ; var randomNumber = ( Math . floor ( randomNum * ( myMax - myMin + 1 ) ) + myMin ) ; console . log ( randomNumber ) ; var numberGuess ; var guesses = 0 ; while ( guesses < 4 ) { numberGuess = prompt ( 'Guess a number between 1 and 20. Hint: keep it to integers' ) ; console . log ( numberGuess ) ; if ( numberGuess > randomNumber ) { alert ( 'Try something a little lower' ) ; console . log ( 'Try something a little lower' ) ; } else if ( numberGuess < randomNumber ) { alert ( 'Try something a little higher' ) ; console . log ( 'Try something a little higher' ) ; } guesses ++ ; console . log ( guesses ) ; if ( guesses === 4 ) { alert ( 'Sorry, you are out of guesses' ) ; console . log ( 'Sorry, you are out of guesses' ) ; } else if ( numberGuess == randomNumber ) { alert ( 'Nice, you guessed correctly' ) ; console . log ( 'Nice, you guessed correctly' ) ; correctGuesses = ( correctGuesses + 1 ) ; break ; } else { alert ( 'Why don\'t you give it another shot. You have ' + ( 4 - guesses ) + ' left' ) ; } } }
create random number for question 6
create random number for question 6
// Assign variables for 6th question // This while loop checks if prompt value is my randomNumber