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 — javascript/conditional/concatenate.md at master · Amitkm-450/javascript

Expand file tree

/

concatenate.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
51 lines (41 loc) · 1.53 KB
/

concatenate.md

Copy path

File metadata and controls

51 lines (41 loc) · 1.53 KB
Raw
Copy raw file
Download raw file
Edit and raw actions

Concatenate conditions

Furthermore you can concatenate different conditions with "or” or “and” statements, to test whether either statement is true, or both are true, respectively.

In JavaScript “or” is written as || and “and” is written as &&.

Say you want to test if the value of x is between 10 and 20—you could do that with a condition stating:

if (x > 10 && x < 20) {
    ...
}

If you want to make sure that country is either “England” or “Germany” you use:

if (country === "England" || country === "Germany") {
    ...
}

Note: Just like operations on numbers, Condtions can be grouped using parenthesis, ex: if ( (name === "John" || name === "Jennifer") && country === "France").

{% exercise %} 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" {% initial %} var name = "John"; var country = "England"; var primaryCategory, secondaryCategory;

if ( /_ Fill here / ) { primaryCategory = "E/J"; } if ( / Fill here _/ ) { secondaryCategory = "E|J"; } {% solution %} var name = "John"; var country = "England"; var primaryCategory, secondaryCategory;

if (name === "John" && country === "England") { primaryCategory = "E/J"; } if (name === "John" || country === "England") { secondaryCategory = "E|J"; } {% validation %} assert(primaryCategory === "E/J" && secondaryCategory === "E|J"); {% endexercise %}

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.