Repository navigation
Expand file tree
/
Copy pathSJ_11_Exercise.html
More file actions
71 lines (68 loc) · 2.33 KB
/
Copy pathSJ_11_Exercise.html
File metadata and controls
71 lines (68 loc) · 2.33 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//Q.1 Create object to represent a product from myntra
let product={
name: 'Jeans',
size: 'S',
fit: 'Slim Fit',
'delivery-time': 'Same day delivery',
};
//Q.2 create an object with 2 references & log changes to one object by changing the other one
let copyProduct = product;
console.log(product);
copyProduct.size= 'M';
console.log(product);
copyProduct.fit='Regular Fit';
console.log(product);
//Q.3 use bracket notation to display delivery-time
console.log(product['delivery-time']);
//Q.4 give an object {message:'good job', status:'complete'}, use de-structuring to create 2 variables message & status
let obj={
message : 'good job',
status: 'complete ',
};
console.log(obj);
let{message , status}= obj;
console.log(message, status);
//Q.5 Add function isIdenticalProduct to compare two product objects
function isIdenticalProduct(product1, product2){
if(typeof product1 !== 'object' || typeof product2!== 'object'){
console.warn('Parameter passed was not an object');
return false;
}
if(product1== product2){
return true;
}
if(product1.name===product2.name && product1.size === product2.size && product1.fit === product2.fit){
return true;
}
else{
return false;
}
}
let product2={
name: 'Jeans',
size: 'M',
fit: 'Slim Fit',
'delivery-time': 'Same day delivery',
};
let product3={
name: 'Jeans',
size: 'M',
fit: 'Slim Fit',
'delivery-time': 'Same day delivery',
};
console.log(isIdenticalProduct(product,product2));
console.log(isIdenticalProduct(product,''));
console.log(isIdenticalProduct(product,product));
console.log(isIdenticalProduct(product2,product3));
</script>
</body>
</html>