index.js
//Officially starting the Reverse Number Guessing Game

Officially starting the Reverse Number Guessing Game
Officially starting the Reverse Number Guessing Game
async function start2() {
  console.log(
    "Welcome to the Second Number Guessing Game! In THIS version, you (the human) can try to guess a secret number that I (the CPU) will think of."
  );
  console.log(
    "First. Let us set some parameters before the game begins.\nI don't wanna make this too easy or too hard on you so I'll let you set the range of numbers that I have to work with."
  );
  let minimum = await ask("What's the lowest number you can think of? ");
  if (minimum < 0) {
    console.log(
      "Sorry but my programmer wasn't smart enough to let me deal with negative numbers.\nYou can blame him for what I'm about to do "
    );
    process.exit();
  }
  let maximum = await ask(
    "What's the HIGHEST number I can go up to :D?\nYou might not wanna make this too far from your low. You may have a tougher time... "
  );
  if (maximum === minimum) {
    console.log("Yeah no that's not gonna work for this game.");
    process.exit();
  }
  let cpusNumber = randomNum(minimum, maximum);
  console.log(
    "Thank you very much for your cooperation.\nNow that we got the specifics out of the way... "
  );
  let secretGuess = await ask(
    "Care to press your luck friend?\nI bet you won't figure it out right away X)\nWhat's your guess? "
  );
  secretGuess = parseInt(secretGuess);
  console.log("You entered: " + secretGuess);
  let count = ``;
  if (cpusNumber === secretGuess) {
    console.log("You got it on the FIRST TRY!");
  } else {
    while (cpusNumber !== secretGuess) {
      if (cpusNumber < secretGuess) {
        secretGuess = await ask("It's lower than that, guess again! ");
        secretGuess = parseInt(secretGuess);
        count++;
      } else if (cpusNumber > secretGuess) {
        secretGuess = await ask("It's higher than that, try again! ");
        secretGuess = parseInt(secretGuess);
        count++;
      }
      console.log(
        `Nice work! And now that you FINALLY guessed my number...in ${count} try/s no less\n`
      );
      let tryagain = await ask("How bout we try this game again? ");
      if (tryagain === "yes") {
        console.log("ALLLRRIIIGHHHTTT!");
        start2();
      } 
      else if (tryagain === "no");
      {
        let tryagain2 = await ask("Care to try something else ");
        if (tryagain2 === "yes") {
          console.log(
            "Sounds good. I'll take you back to the main menu now :D"
          );
          init();
        } 
        else {
          console.log(
            "Awww. I bet you would have gotten it next time. Oh well"
          );
          process.exit();
        }
      }
    }
  }
}
async function start2 ( ) { console . log ( "Welcome to the Second Number Guessing Game! In THIS version, you (the human) can try to guess a secret number that I (the CPU) will think of." ) ; console . log ( "First. Let us set some parameters before the game begins.\nI don't wanna make this too easy or too hard on you so I'll let you set the range of numbers that I have to work with." ) ; let minimum = await ask ( "What's the lowest number you can think of? " ) ; if ( minimum < 0 ) { console . log ( "Sorry but my programmer wasn't smart enough to let me deal with negative numbers.\nYou can blame him for what I'm about to do " ) ; process . exit ( ) ; } let maximum = await ask ( "What's the HIGHEST number I can go up to :D?\nYou might not wanna make this too far from your low. You may have a tougher time... " ) ; if ( maximum === minimum ) { console . log ( "Yeah no that's not gonna work for this game." ) ; process . exit ( ) ; } let cpusNumber = randomNum ( minimum , maximum ) ; console . log ( "Thank you very much for your cooperation.\nNow that we got the specifics out of the way... " ) ; let secretGuess = await ask ( "Care to press your luck friend?\nI bet you won't figure it out right away X)\nWhat's your guess? " ) ; secretGuess = parseInt ( secretGuess ) ; console . log ( "You entered: " + secretGuess ) ; let count = ` ` ; if ( cpusNumber === secretGuess ) { console . log ( "You got it on the FIRST TRY!" ) ; } else { while ( cpusNumber !== secretGuess ) { if ( cpusNumber < secretGuess ) { secretGuess = await ask ( "It's lower than that, guess again! " ) ; secretGuess = parseInt ( secretGuess ) ; count ++ ; } else if ( cpusNumber > secretGuess ) { secretGuess = await ask ( "It's higher than that, try again! " ) ; secretGuess = parseInt ( secretGuess ) ; count ++ ; } console . log ( ` ${ count } \n ` ) ; let tryagain = await ask ( "How bout we try this game again? " ) ; if ( tryagain === "yes" ) { console . log ( "ALLLRRIIIGHHHTTT!" ) ; start2 ( ) ; } else if ( tryagain === "no" ) ; { let tryagain2 = await ask ( "Care to try something else " ) ; if ( tryagain2 === "yes" ) { console . log ( "Sounds good. I'll take you back to the main menu now :D" ) ; init ( ) ; } else { console . log ( "Awww. I bet you would have gotten it next time. Oh well" ) ; process . exit ( ) ; } } } } }
Officially starting the Reverse Number Guessing Game
Officially starting the Reverse Number Guessing Game
//requesting range parameters from player
 //request to set the minimum number
 //error handing. the game cannot handle using negative numbers so I needed to set this condition
 //game ends 
 //request to set the maximum number
 //the game will break if the min and max are the same so there is a conditional set to handle this possibility
 //the CPU's number randomly generated guess according to the min and max params set by the user
 //sets a count so player will know how many times it took to find the correct answer
 // upon the wrong guess, player triggers a while loop that runs until guess is correct
 // if a guess is higher, CPU gives player a hint and prompts a new guess
 //count goes up by one
 // if a guess is lower, CPU gives player a hint and prompts a new guess
 //count goes up by one
 //asks the player if they wish to play another round of this game again
 //should they respond yes, a new round of Game 2 is triggered 
 //should they say no, player is prompted a new question
 //asks if player wants to try the other number game
 //if response is yes, player is taken back to the start of the program
 //any other input triggers the program to close
