species: "greyhound",
weight: 60,
age: 4
};
var species = dog["species"];
// fill in the code to save the weight and age using bracket notation
var weight = dog["weight"];
var age = dog["age"];
============================================================
var bicycle = new Object();
bicycle.speed=0;
bicycle.gear=1;
bicycle.frame_material="carbon fiber";
var bicycle = {
frame_material: "carbon fiber",
speed: 0,
gear: 1,
};
==================================================================
var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
// here is our method to set the height
rectangle.setHeight = function (newHeight) {
this.height = newHeight;
};
// help by finishing this method
rectangle.setWidth = function (newWidth) {
this.width = newWidth;
};
// here change the width to 8 and height to 6 using our new methods
rectangle.setWidth(8);
rectangle.setHeight(6);
===============================================================
function Person(name,age) {
this.name = name;
this.age = age;
this.species = "Homo Sapiens";
}
=============================================================
function family (name,age){
this.name = name;
this.age = age;
}
var family = newArray();
=============================================================
// 3 lines required to make harry_potter
var harry_potter = new Object();
harry_potter.pages = 350;
harry_potter.author = "J.K. Rowling";
// A custom constructor for book
function Book (pages, author) {
this.pages = pages;
this.author = author;
}
// Use our new constructor to make the_hobbit in one line
var the_hobbit = new Book(the_hobbit.pages,the_hobbit.author);
the_hobbit.pages = 320;
the_hobbit.author = "J.R.R. Tolkien";
============================================================
var gabby = new Person("minh",19);
// add a "speak" method to Person!
this.speak = function() {
console.log("Hello!");
};
0 nhận xét:
Đăng nhận xét