GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add article about concatenate conditions · viijayscript/javascript@216d03d

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • SUMMARY.md
  • conditional
    • concatenate.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎SUMMARY.md‎

Copy file name to clipboardExpand all lines: SUMMARY.md
+2-1Lines changed: 2 additions & 1 deletion
  • Display the source diff
  • Display the rich diff
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)
Collapse file

‎conditional/concatenate.md‎

Copy file name to clipboard
+59Lines changed: 59 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
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 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.