// // guess a number game: the program picks a random number between 1 and 100, and asks you to guess it // - recursive function call var inquirer = require("inquirer"); var secret = Math.floor( Math.random()* 100 ) + 1; var questions = [ { type: 'input', name: 'guess', message: "What's your guess?" } ] var yourGuess = -1; function ask() { inquirer.prompt(questions).then(answers => { console.log( "You guessed: " , answers.guess); yourGuess = answers.guess; if (yourGuess != secret) { // With or without this hint of "larger" or "smaller" // you have two different approaches to make a guess // computational complexity concept: Liner - O(N), vs Log - O(logN) // if( yourGuess < secret) { console.log("larger!") } else if (yourGuess > secret) { console.log("smaller") } ask(); } else { console.log('Congratulation, you guessed right: ', yourGuess); } }); } ask();