generated from justsml/exercises-template
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
index.js
79 lines (64 loc) · 2.57 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
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
// 👇 COMPLETE YOUR WORK BELOW 👇
/* ❗❗ NOTE: PLEASE USE INDIVIDUAL KEYS FOR YOUR CONSTRUCTOR PARAMETERS, NOT OBJECTS. THE TESTS WILL NOT PASS WITH OBJECTS. ❗❗ */
/*
TASK 1
- Write a Person Constructor that initializes `name` and `age` from arguments.
- All instances of Person should initialize with an empty `stomach` array.
- Give instances of Person the ability to `.eat("someFood")`:
+ .eat() should recieve a string as a parameter and take some type of edible as an argument
+ When eating an edible, it should be pushed into the `stomach` array.
+ The `eat` method should have no effect if there are 10 items in the `stomach` array.
- Give instances of Person the ability to `.poop()`:
+ When an instance poops, its `stomach` array should be empty.
- Give instances of Person a method `.toString()`:
+ It should return a string with `name` and `age`. Example: "Mary, 50"
*/
function Person() {
}
/*
TASK 2
- Write a Car constructor that initializes `model` and `milesPerGallon` from arguments.
- All instances built with Car:
+ should initialize with an `tank` at 0
+ should initialize with an `odometer` at 0
- Give cars the ability to get fueled with a `.fill(gallons)` method
+ should take 'gallons' as an parameter which will take number of gallons as an argument
+ should add the gallons to `tank`.
- STRETCH: Give cars ability to `.drive(distance)`. The distance driven:
+ Should cause the `odometer` to go up.
+ Should cause the the `tank` to go down taking `milesPerGallon` into account.
- STRETCH: A car which runs out of `fuel` while driving can't drive any more distance:
+ The `drive` method should return a string "I ran out of fuel at x miles!" x being `odometer`.
*/
function Car() {
}
/*
TASK 3
- Write a Baby constructor subclassing Person.
- Besides `name` and `age`, Baby takes a third argument to initialize `favoriteToy`.
- Besides the methods on Person.prototype, babies also have the ability to `.play()`:
+ Should return a string "Playing with x", x being the favorite toy.
*/
function Baby() {
}
/*
TASK 4
In your own words explain the four principles for the "this" keyword below:
1.
2.
3.
4.
*/
///////// END OF CHALLENGE /////////
/* 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 */
function foo(){
console.log('its working!');
return 'bar';
}
foo();
module.exports = {
foo,
Person,
Car,
Baby
}