You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit b137d8f
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: javascript/building-blocks/tasks/conditionals/marking.md
+6-40Lines changed: 6 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,12 +35,12 @@ You need to create one `if ... else` structure that checks whether the machine i
35
35
36
36
Inside the `if` part, you need to nest an `if ... else if` structure that puts appropriate messages into the `response` variable depending on different scores. The conditional operator tests should look like this:
37
37
38
-
*`score < 0 || score > 100` - "This is not possible, an error has occurred." This could also be done just by an `else` clause, as the scores between 0 and 100 are all covered by the other clauses. But it's nice to be exact.
39
-
*`score >= 0 && score < 20` - "That was a terrible score — total fail!"
40
-
*`score >= 20 && score < 40` - "You know some things, but it\'s a pretty bad score. Needs improvement."
41
-
*`score >= 40 && score < 70` — "You did a passable job, not bad!"
42
-
*`score >= 70 && score < 90` — "That\'s a great score, you really know your stuff."
43
-
*`score >= 90 && score <= 100` — "What an amazing score! Did you cheat? Are you for real?"
38
+
-`score < 0 || score > 100` - "This is not possible, an error has occurred." This could also be done just by an `else` clause, as the scores between 0 and 100 are all covered by the other clauses. But it's nice to be exact.
39
+
-`score >= 0 && score < 20` - "That was a terrible score — total fail!"
40
+
-`score >= 20 && score < 40` - "You know some things, but it\'s a pretty bad score. Needs improvement."
41
+
-`score >= 40 && score < 70` — "You did a passable job, not bad!"
42
+
-`score >= 70 && score < 90` — "That\'s a great score, you really know your stuff."
43
+
-`score >= 90 && score <= 100` — "What an amazing score! Did you cheat? Are you for real?"
44
44
45
45
The finished code should look something like this:
46
46
@@ -70,40 +70,6 @@ if (machineActive) {
70
70
71
71
## Task 3
72
72
73
-
In this task we want you to take the code you wrote for the previous example, and convert it so that the inner structure uses a `switch` statement.
74
-
75
-
Use the switch `default` option for the "not possible" option.
76
-
77
-
The full `if ... else` block including added `switch` statement should look like this:
78
-
79
-
```
80
-
if (machineActive) {
81
-
switch (true) {
82
-
case (score >= 0 && score < 20):
83
-
response = 'That was a terrible score — total fail!';
84
-
break;
85
-
case (score >= 20 && score < 40):
86
-
response = 'You know some things, but it\'s a pretty bad score. Needs improvement.';
87
-
break;
88
-
case (score >= 40 && score < 70):
89
-
response = 'You did a passable job, not bad!';
90
-
break;
91
-
case (score >= 70 && score < 90):
92
-
response = 'That\'s a great score, you really know your stuff.';
93
-
break;
94
-
case (score >= 90 && score <= 100):
95
-
response = 'What an amazing score! Did you cheat? Are you for real?';
96
-
break;
97
-
default:
98
-
response = 'This is not possible, an error has occurred.';
99
-
}
100
-
} else {
101
-
response = 'The machine is turned off. Turn it on to process your score.';
102
-
}
103
-
```
104
-
105
-
## Task 4
106
-
107
73
For the final task we have to offer in this set, we need you to first write an `if ... else` statement that checks whether `machineActive` is `true`. If so, set `machineResult` to a string telling the user they can successfully log in. If not, set it to a message telling them they need to activate the machine before they can log in.
108
74
109
75
Inside the `if` part of the structure, you need to write a ternary operator that checks whether `pwd` is equal to `cheese`. If so, it assigns a string saying that the login was successful; if not assign a string saying the log in failed. The result should be assigned to a variable called `pwdResult`.
0 commit comments