-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
81 lines (60 loc) · 2.05 KB
/
app.js
File metadata and controls
81 lines (60 loc) · 2.05 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
65
66
67
68
69
70
71
72
73
74
75
76
77
/* The four rules for 'this';
* in your own words. explain the four rules for the "this" keyword below.
* 1.
* 2.
* 3.
* 4.
* write out a code example of each explanation above
*/
// First Rule
// Second Rule
// Third Rule
// Fourth Rule * you may want to use your third rule's example to accomplish this
// explain closure
function foo () {
console.log(this); // what does this point to?
};
const counterFunction = () => {
// this code is broken. figure out why, and tell us where the closure is when you fix it
const changeCount = (value) => {
count += value;
};
return {
increment: () => {
changeCount(1);
},
decrement: () => {
changeCount(-1);
},
total: () => {
return count;
}
}
};
const counter = counterFunction();
counter.increment();
counter.increment();
counter.increment();
counter.increment();
counter.increment();
console.log(counter.total());
// create a constructor function called "Car"
// car takes an options object as its only argument
// your options object should have "make", "model", "year" properties on it
// assign these properties you pass in with options to the constructors 'this' object.
// add a speak() method to your object that when called will log out the car's make model and year.
// when you're done un comment the next few lines and run the file here in node `node app.js`.
// const herby = new Car({make: 'Volkswagen', model: 'Beetle', year: '1963'});
// console.log(herby.speak());
// const goldfinger = new Car({make: 'Aston Martin', model: 'DB5', year: '1964'});
// console.log(goldfinger.speak());
// once you get done with this, redo it all using the class keyword and a constructor function.
// extra credit
// we didn't touch on Recursion in the lecture yet, but you're going to build a recursive function now
let n = 10;
while(n >= 1) {
console.log(n);
n--;
}
// write a function called countDown that does the exact same thing as above, but calls itself until it can't anymore.
// hint-> your base case will look like the logic in the while loop.