b5eafe3bb0f9c687cb4a2a7e4c221d4a
javascript1
lab5
v2
rasb14
2018-11-27 16:15:55
v3.1.3 (2018-09-13)

Generated 2018-11-27 17:15:55 by dbwebb lab-utility v3.1.3 (2018-09-13).


Lab 5 - objects

Practice basics on objects.

1. Create object

Start by creating an empty object called person by using the object literal.

Exercise 1.1 (1 points)

Give your person-object the property firstName with a value of "Isaac". Add a method called print1() that returns a presentation of the object, like this: "My name is Isaac."
Use this.firstName to construct the string.

Answer with the result from calling person.print1().

Exercise 1.2 (1 points)

Add properties lastName and nationality to your person-object. Their values should be "Newton" and "England".

Create the method person.print2() which should say: "My name is Isaac Newton from England.".

Exercise 1.3 (1 points)

Add the property born with the value of a Date object: "1643-01-04".

Create a method print3() that says exactly the same as print2() followed by "I was born 1643.".

Exercise 1.4 (1 points)

Create a second person, called person2 by using built-in function Object.create().

person2 should have the following properties: "Henri", "Becquerel", "France", "1852-12-15".

Print out details on the second person using person2.print3().

Exercise 1.5 (1 points)

Add the method, init(firstName, lastName, nationality, born), to your Person-object. The method should help you create new Person-objects.

Try it out using the following properties: "Albert", "Einstein", "Germany", "1879-03-14".

Name the variable holding the person person3.

Print out details on the third person using person3.print3().


b5eafe3bb0f9c687cb4a2a7e4c221d4a