-
Notifications
You must be signed in to change notification settings - Fork 0
/
Day 4
47 lines (33 loc) · 1.1 KB
/
Day 4
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
DAY 4
Instructions
(This challenge is worth 5 points)
Click here to learn how to navigate the code editor
Opposites hm? In our daily lives, an opposite can mean multiple things, but in programming, it's different. Opposites can only be used when dealing with logical expressions or booleans. Knowing that the property inside our toggle is called isOn, we can infer that the value attached to it is either true, or false.
Create a function that takes in a toggle object and will change the value of the property isOn between true and false and return the updated object. Using the function twice should revert the toggle back to its original value.
Examples
Input:
const someToggle = {
name:"toggleA",
isOn:false
}
Output:
const someToggle = {
name:"toggleA",
isOn:true
}
Input:
// If ran twice
const someToggle = {
name:"toggleB",
isOn:true
}
Output:
const someToggle = {
name:"toggleB",
isOn:true
}
SOLUTION
function switchToggle(toggle){
toggle.isOn = !toggle.isOn;
return toggle
}