-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathindex.js
51 lines (38 loc) · 1.19 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'use strict';
var readline = require('readline');
console.log("Hello class!");
var scanner = readline.createInterface({
input: process.stdin,
output: process.stdout
});
var questions = [
"What is your name? ",
"What is your favorite color? "
];
var answers = [];
var currentQuestion = 0;
var askQuestion = function(answer) {
answers.push(answer);
//go onto next question!
currentQuestion = currentQuestion+1; //go to next question
if(currentQuestion < questions.length) { //recursive condition
scanner.question(questions[currentQuestion], askQuestion);
}
else {
console.log("Answers: " + answers);
scanner.close();
}
}
// var colorAnswer = function(color) {
// answers.push(color);
// //console.log("Your favorite color is: "+color);
// scanner.question("What is your favorite color? ", colorAnswer);
// scanner.close();
// };
// scanner.question("What is your name?", function(name){
// answers.push(name);
// scanner.question("What is your favorite color? ", colorAnswer);
// });
//console.log("I'm waiting... ");
//launch the recursion
scanner.question(questions[currentQuestion], askQuestion);