Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 34 additions & 13 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,23 @@
+ It should return a string with `name` and `age`. Example: "Mary, 50"
*/

function Person() {

function Person(name, age) {
this.name = name;
this.age = age;
this.stomach = [];
}
Person.prototype.eat = function(edible){
if(this.stomach.length < 10){
this.stomach.push(edible);
}


}
Person.prototype.poop = function(){
this.stomach = [];
}
Person.prototype.toString = function(){
return `${this.name}, ${this.age}`;
}
/*
TASK 2
- Write a Car constructor that initializes `model` and `milesPerGallon` from arguments.
Expand All @@ -36,8 +48,14 @@ function Person() {
+ The `drive` method should return a string "I ran out of fuel at x miles!" x being `odometer`.
*/

function Car() {

function Car(model, mpg) {
this.model = model;
this.milesPerGallon = mpg;
this.tank = 0;
this.odometer = 0;
}
Car.prototype.fill = function(gallons){
this.tank = this.tank + gallons;
}


Expand All @@ -49,18 +67,21 @@ function Car() {
+ Should return a string "Playing with x", x being the favorite toy.
*/

function Baby() {

function Baby(name, age, favoriteToy) {
Person.call(this, name, age);
this.favoriteToy = favoriteToy;
}
Baby.prototype = Object.create(Person.prototype);
Baby.prototype.play = function(){
return `Playing with ${this.favoriteToy}`;
}


/*
TASK 4
In your own words explain the four principles for the "this" keyword below:
1.
2.
3.
4.
1. window binding -when no other rules apply will return the window/global object in undefined in strict mode.
2. implicit binding - this is refered to when we look at a function that invoked we look to the left of the dot.
3. explicit binding - this refers to the .call , . apply, and .bind".
4. new binding - This is when a constructor function is created this points to the new object created.
*/

///////// END OF CHALLENGE /////////
Expand Down
Loading