diff --git a/index.js b/index.js index 43db2abe..b1fb34c7 100644 --- a/index.js +++ b/index.js @@ -15,10 +15,25 @@ + 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 (someFood) { + if (this.stomach.legnth !== 10) { + this.stomach.push(someFood); + } +}; + +Person.prototype.poop = function () { + this.stomach = []; +}; + +Person.prototype.toString = function () { + return `${this.name}, ${this.age}`; +}; /* TASK 2 @@ -36,10 +51,18 @@ 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, milesPerGallon) { + this.model = model; + this.milesPerGallon = milesPerGallon; + this.tank = 0; + this.odometer = 0; } +Car.prototype.fill = function (gallons) { + this.tank += gallons; +}; + +// const greenCar = new Car(model, milesPerGallon); /* TASK 3 @@ -49,10 +72,15 @@ 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 @@ -66,14 +94,14 @@ function Baby() { ///////// END OF CHALLENGE ///////// /* 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 Please do not modify anything below this line 🛑🛑🛑🛑🛑🛑🛑🛑🛑🛑 */ -function foo(){ +function foo() { console.log('its working!'); return 'bar'; } foo(); module.exports = { foo, - Person, + Person, Car, - Baby -} + Baby, +}; diff --git a/package-lock.json b/package-lock.json index d758c657..4a96a12c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "codegraded-project-js", - "version": "0.0.8", + "version": "0.0.9", "devDependencies": { "@babel/core": "7.17.8", "@babel/plugin-transform-runtime": "7.17.0",