forked from LEARNAcademy/JS-foundations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects-practice-1.js
38 lines (26 loc) · 1.73 KB
/
objects-practice-1.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Objects Practice 1: Accessing Properties
// Below are exercises in accessing the properties of Javascript Objects. Beneath each prompt write the code to fulfill the exercise requirement.
// Exercise 1
// Consider this variable:
var person = { fName: "Arthur", lastName: "Dent" }
// Write the code that uses dot notation to access the first name of the person object.
// Exercise 2
// Write the code that uses dot notation to access the last name of the person object.
// Exercise 3
// Write the code that uses bracket notation to access the first name of the person object.
// Exercise 4
// Write the code that uses bracket notation to access the last name of the persion object.
// Exercise 5
// Update the person object to have a method called fullName that returns the first and last name of the person object in one string. Call the method below.
// Exercise 6
// Consider this variable.
var lunch = { name: "PB and Banana", type: "sandwich", ingredients: ["bread", "peanut butter", "banana"] }
// Write the code that accesses the ingredients property of the lunch object. Provide the answer in dot and bracket notation.
// Exercise 7
// Write the code that accesses the first item in the ingredients property of the lunch object. Provide the answer in dot and bracket notation.
// Exercise 8
// Write the code that accesses the second item in the ingredients property of the lunch object. Provide the answer in dot and bracket notation.
// Exercise 9
// Write a function that takes an object like the one above and returns "The ingredients for a PB and Banana sandwich are bread, peanut butter, and banana."
// Exercise 10
// Add a method to the object that returns "The ingredients for a PB and Banana sandwich are bread, peanut butter, and banana."