forked from Faruq-Hameed/js-basics2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app3.js
108 lines (75 loc) · 2.91 KB
/
app3.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
///////////// Exercises 1 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const address = {
street: 'Nurudeen street',
city: 'Faruq City',
zipCode: '1234'
}
function showAddress(address) {
for (let key of Object.keys(address))
console.log(key+': ', address[key])
}
// showAddress(address)
// ///////////////////Exercises 2///////////////////////////////////////////////////////// //////////////////////////////////////
function createAddress(address){
return address
}
const addressNew = createAddress(address)// using factory function
// console.log(addressNew);
// console.log(addressNew.city)
function CreateAddress(address){
this.address = address;
return this.address
}
const newAddress = new CreateAddress(address) // using constructor function
//////////////////////////Exercises 3/////////////////////////////////////////////// ////////////////////////////////// ///////////////////////////////
const address1 = new CreateAddress(address);
const address2 = new CreateAddress(address);
function areEqual(a,b) {
if (a === b) console.log(true); else console.log(false);
}
// areEqual(address1, address2);
function areSame(a, b) {
if (a === address && b === address1) console.log(true); else console.log('false');
}
// areSame(address1, address2);
/////////////////////////Exercises 4///////////////////////////////////////////////////////////////////////////////////////////////////////
const blogPost = {
title: 'Nurudeen',
body: 'Lorem ipsum dolor sit amet consectetur adipisicing elit.',
author: 'Duece',
views: 25,
comments: {
comment1: {
author: 'Nurudeen',
body: 'Lorem ipsum dolor sit amet consectetur adip',
isLive: true,
},
comment2: {
author: 'Faruq',
body: 'Lorem ipsum dolor sit amet consectetur adip',
isLive: true,
},
comment3: {
author: 'Deuce',
body: 'Lorem ipsum dolor sit amet consectetur adip',
isLive: false,
},
}
}
// console.log(blogPost.comments.comment3.isLive)
//////////////////////////Exercise 5//////////////////////////////////////////////////////////////////////////////////////////////
let programming = {
languages: ["JavaScript", "Python", "Ruby"],
isChallenging: true,
isRewarding: true,
difficulty: 8,
jokes:"http://stackoverflow.com/questions/234075/what-is-your-best-programmer-joke"
};
programming.languages.push('Go'); //(1)//
programming.difficulty = 7; //(2)//
delete programming.jokes; //(3)//
programming.isFun = true //(4)//
for (language of programming.languages) console.log(language ); //(5)//
for (let key of Object.keys(programming)) console.log(key); //(6)//
for (let key of Object.keys(programming)) console.log(programming[key]); //(7)//
// console.log(programming);