Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

completed coursework #262

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
57 changes: 50 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +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(food) {
if(this.stomach.length <= 9){
this.stomach.push(food);
}
}

Person.prototype.poop = function() {
this.stomach.length = 0;
}

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 +50,29 @@ 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;
this.drive = function (distance) {
let current = 0
for(i<0;i<distance;i++){
if(current === honk.milesPerGallon){
current = 0
this.tank -= 1
}
else if(tank === 0){
return(`I ran out of fuel at ${this.odometer} miles!`);
}
this.odometer + 1
current + 1
}
}
}

Car.prototype.fill = function (gallons) {
this.tank += gallons
}


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

function Baby() {
function Baby(name,age,favoriteToy) {
this.name = name;
this.age = 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. Create a new parameter to exist outside of the Window scope
2. ties each parameter to a value or word
3. invoke said words
4. pass them to another value tied to its scope
*/

///////// END OF CHALLENGE /////////
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.