-
Notifications
You must be signed in to change notification settings - Fork 0
/
Task-3.1.js
78 lines (60 loc) · 1.68 KB
/
Task-3.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
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
var cat = {
"name": "Fluffy",
"activities": ["play", "eat cat food"],
"catFriends": [
{
"name": "bar",
"activities": ["be grumpy", "eat bread omblet"],
"weight": 8,
"furcolor": "white"
},
{
"name": "foo",
"activities": ["sleep", "pre-sleep naps"],
"weight": 3
}]
}
///Height and weight ////
cat.height=5;
cat.weight=10;
///Rename cat's Name ///
cat.name="Fluffyy";
///List activities of cat Friends///
for(i =0; i< cat.catFriends.length; i++){
for(j =0; j< cat.catFriends[i].activities.length; j++){
console.log(cat.catFriends[i].activities[j]);
}
}
////Print Cat Friend Name's ///
for (i=0; i<cat.catFriends.length; i++){
console.log(cat.catFriends[i].name);
}
////Print's total weight of cat's friends///
var totalWeight = []
for ( i=0 ; i<cat.catFriends.length; i++){
totalWeight += cat.catFriends[i].weight;
}
console.log(totalWeight);
//// Activities of all cat's////
var cat1 = cat.activities;
var cat2 = " "
for(i =0; i< cat.catFriends.length; i++){
for(j =0; j< cat.catFriends[i].activities.length; j++){
cat2 += cat.catFriends[i].activities[j];
}
}
console.log(cat2)
console.log(cat1)
////Adding New Activites////
var newActivities = ['spinning', 'eating'];
cat.catFriends[0].activities.push(...newActivities);
cat.catFriends[1].activities.push(...newActivities);
for(i =0; i< cat.catFriends.length; i++){
for(j =0; j< cat.catFriends[i].activities.length; j++){
console.log(cat.catFriends[i].activities[j]);
}
}
///Update Fur Color//
cat.catFriends[0].furcolor = "red"
console.log(cat.catFriends[0].furcolor);
console.log(cat.name);