-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammers2.js
More file actions
64 lines (59 loc) · 2.34 KB
/
Copy pathprogrammers2.js
File metadata and controls
64 lines (59 loc) · 2.34 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
// dependency for inquirer npm package
var inquirer = require("inquirer");
// constructor function used to create programmers objects
function Programmer(name, position, age, language) {
this.name = name;
this.position = position;
this.age = age;
this.language = language;
}
// creates the printInfo method and applies it to all programmer objects
Programmer.prototype.printInfo = function() {
console.log("Name: " + this.name + "\nPosition: " + this.position +
"\nAge: " + this.age + "\nLanguages: " + this.language);
};
// variable we will use to count how many times our questions have been asked
var count = 0;
var askQuestion = function() {
// if statement to ensure that our questions are only asked five times
if (count < 5) {
// runs inquirer and asks the user a series of questions whose replies are
// stored within the variable answers inside of the .then statement
inquirer.prompt([
{
name: "name",
message: "What is your name?"
}, {
name: "position",
message: "What is your current position?"
}, {
name: "age",
message: "How old are you?"
}, {
name: "language",
message: "What is your favorite programming language?"
}
]).then(function(answers) {
// initializes the variable newProgrammer to be a programmer object which will take
// in all of the user's answers to the questions above
var newProgrammer = new Programmer(
answers.name,
answers.position,
answers.age,
answers.language);
// printInfo method is run to show that the newProgrammer object was successfully created and filled
newProgrammer.printInfo();
// add one to count to increment our recursive loop by one
count++;
// run the askquestion function again so as to either end the loop or ask the questions again
askQuestion();
});
// else statement which prints "all questions asked" to the console
// when the code has been run five times
}
else {
console.log("All questions asked");
}
};
// call askquestion to run our code
askQuestion();