-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogrammers.js
More file actions
43 lines (40 loc) · 1.59 KB
/
Copy pathprogrammers.js
File metadata and controls
43 lines (40 loc) · 1.59 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
// 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);
};
// for loop to run the prompt multiple times... right?
for (var i = 0; i < 5; i++) {
// 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();
});
}