Skip to content

Commit 216d03d

Browse files
committed
Add article about concatenate conditions
1 parent 6898c52 commit 216d03d

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@
1515
* [Conditional Logic](conditional/README.md)
1616
* [If](conditional/if.md)
1717
* [Else](conditional/else.md)
18-
* [Comparators](conditional/comparators.md)
18+
* [Comparators](conditional/comparators.md)
19+
* [Concatenate](conditional/concatenate.md)

conditional/concatenate.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Concatenate conditions
2+
3+
Furthermore you can concatenate different conditions with "or” or “and” statements, to test whether either statement is true, or both are true, respectively.
4+
5+
In JavaScript “or” is written as `||` and “and” is written as `&&`.
6+
7+
Say you want to test if the value of x is between 10 and 20—you could do that with a condition stating:
8+
9+
```
10+
if(x > 10 && x < 20) {
11+
...
12+
}
13+
```
14+
15+
If you want to make sure that country is either “England” or “Germany” you use:
16+
17+
```
18+
if(country === 'England' || country === 'Germany') {
19+
...
20+
}
21+
```
22+
23+
**Note**: Just like operations on numbers, Condtions can be grouped using parenthesis, ex: ```if ( (name == "John" || name == "Jennifer") && country == "France")```.
24+
25+
---
26+
27+
Fill up the 2 conditions so that `primaryCategory` equals `"E/J"` only if name equals `"John"` and country is `"England"`, and so that `secondaryCategory` equals `"E|J"` only if name equals `"John"` or country is `"England"`
28+
29+
```js
30+
var name = "John";
31+
var country = "England";
32+
var primaryCategory, secondaryCategory;
33+
34+
if ( /* Fill here */ ) {
35+
primaryCategory = "E/J";
36+
}
37+
if ( /* Fill here */ ) {
38+
secondaryCategory = "E|J";
39+
}
40+
```
41+
42+
```js
43+
var name = "John";
44+
var country = "England";
45+
var primaryCategory, secondaryCategory;
46+
47+
if (name == "John" && country == "England") {
48+
primaryCategory = "E/J";
49+
}
50+
if (name == "John" || country == "England") {
51+
secondaryCategory = "E|J";
52+
}
53+
```
54+
55+
```js
56+
assert(primaryCategory == "E/J" && secondaryCategory == "E|J");
57+
```
58+
59+
---

0 commit comments

Comments
 (0)