forked from gabischool/Week5_JS_Assignment
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.js
More file actions
143 lines (115 loc) ยท 3.49 KB
/
objects.js
File metadata and controls
143 lines (115 loc) ยท 3.49 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
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
Task 1: Gamer Profile Manager ๐ฎ ๐ฎ ๐ฎ ๐ฎ
You are creating a system to manage a gamer's profile.
Steps:
1. Create an object named `gamerProfile` with the following properties:
- `username` (string): The gamer's username.
- `level` (number): The gamer's level.
- `isOnline` (boolean): Whether the gamer is currently online.
2. Write a function `updateOnlineStatus` that:
- Takes the `gamerProfile` object and a boolean `status` as arguments.
- Updates the `isOnline` property based on the `status`.
- Logs: "[username] is now online." or "[username] is now offline."
Example:
Input:
const gamerProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false
};
updateOnlineStatus(gamerProfile, true);
Expected Output:
"ShadowSlayer is now online."
*/
// โ๏ธ Solve it here โ๏ธ
const gameProfile = {
username: "ShadowSlayer",
level: 5,
isOnline: false
};
function updateStatus(profile,status){
profile.isOnline = status;
if (status) {
console.log(`${profile.username} is now online`);
} else {console.log(`${profile.username} is now offline`);
}
}
updateStatus(gameProfile, true);
/*
Task 2: Dress Inventory Checker ๐ ๐ ๐ ๐ ๐
You are helping a fashion designer manage their dress inventory.
Steps:
1. Create an object named `dress` with the following properties:
- `name` (string): Name of the dress.
- `size` (string): Size of the dress.
- `inStock` (boolean): Whether the dress is available.
2. Write a function `checkAvailability` that:
- Takes the `dress` object as an argument.
- Logs: "[name] is available in size [size]." if the dress is in stock.
- Logs: "[name] is out of stock." if the dress is not available.
Example:
Input:
const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};
checkAvailability(dress);
Expected Output:
"Evening Gown is available in size M."
*/
// โ๏ธ Solve it here โ๏ธ
const dress = {
name: "Evening Gown",
size: "M",
inStock: true
};
function checkAvailability(dressItem,){
if (dressItem.inStock) {
console.log(`${dressItem.name} is available in size ${dressItem.size}.`)
} else {console.log(`${dressItem.name} is out of stock. `)
}
}
checkAvailability(dress);
/*
Task 3: Supercar Feature Adder ๐ ๐ ๐ ๐
You are building a configurator for a supercar.
Steps:
1. Create an object named `supercar` with the following properties:
- `model` (string): The car's model.
- `price` (number): The base price.
- `features` (object): An object with a `color` property.
2. Write a function `addFeature` that:
- Takes the `supercar` object and a feature name (string) as arguments.
- Adds the feature to the `features` object and sets it to `true`.
- Logs: "[featureName] has been added to [model]."
3. Use a **for...in loop** to log all the features of the `supercar` object.
Example:
Input:
const supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};
addFeature(supercar, "turbo");
Expected Output:
"Turbo has been added to Ferrari SF90."
Features:
- color: Red
- turbo: true
*/
// โ๏ธ Solve it here โ๏ธ
const supercar = {
model: "Ferrari SF90",
price: 500000,
features: {
color: "Red"
}
};
function addFeature(car,carname) {
car.features[carname] = true;
console.log(`${carname} has been added to ${car.model}`);
}
addFeature(supercar, "turbo");