-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
81 lines (62 loc) · 1.49 KB
/
app.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/** in this lesson I am using object literal syntax to
create objects on the fly. */
var Miggy = {
nombre: 'Miggy',
apellido: 'Mofongo',
direccion: {
calle: 'Car. 2',
ciudad: 'Aguadilla',
pais: 'Puerto Rico'
}
};
function saludar(persona) {
console.log('Hola ' + persona.nombre);
}
function comida(persona){
console.log('Su comida favorita es ' + Miggy.comida);
}
/** these are two functions that will spit out two
* greetings
*/
saludar(Miggy);
/**this function is created on the fly using
* literal sytax
*/
saludar({
nombre: 'Maria',
apellido: 'Almodovar',
})
/**here i use a dot operator to add a new property
* then object literal syntax to define the property
* as an object.
*/
Miggy.comida = {
comida: 'mofongo',
}
const readline = require('readline').createInterface({
input: process.stdin,
output: process.stdout
});
var pet = {
name: "",
trimmedNails: false,
brushedFur: false,
trimNails: function() {
this.trimmedNails = true
},
brushFur: function() {
this.brushedFur = true
},
setName: function(callback) {
readline.question("What do you want to name your pet?", (name) => {
this.name = name;
console.log(`Pet's name set to: ${this.name}`);
readline.close();
if (callback) callback();
})
}
}
let dog = Object.create(pet);
dog.setName(() => {
console.log(`The pet's name is now set to: ${dog.name}`);
})