5 4 1 if statements

Solutions on MaxInterview for 5 4 1 if statements by the best coders in the world

showing results for - "5 4 1 if statements"
Paolo
21 Jul 2020
1/*The condition in an if statement can be any boolean expression, 
2such as name === 'Jack' or points > 10 (here, name and points are 
3variables). Additionally, the code block associated with a conditional 
4can be of any size. This conditional has a code block with two lines of 
5code:*/
6
7if (num % 2 === 0 && num > 3) {
8   console.log(num, "is even");
9   console.log(num, "is greater than 3");
10}
11
12/*While not required, the code within a conditional code block is 
13typically indented to make it more readable. Similarly, it is a common
14convention to place the opening { at the end of the first line, and the 
15closing } on a line of its own following the last line of the code 
16block. You should follow such conventions, even though ignoring them 
17will not create an error.*/
Vanessa
12 Nov 2017
1/*If-else statements allow us to construct two alternative paths. 
2A single condition determines which path will be followed. We can 
3build more complex conditionals using an else if clause. These allow 
4us to add additional conditions and code blocks, which facilitate more 
5complex branching.*/
6
7let x = 10;
8let y = 20;
9
10if (x > y) {
11   console.log("x is greater than y");
12} else if (x < y) {
13   console.log("x is less than y");
14} else {
15   console.log("x and y are equal");
16}
17//x is less than y
Marius
05 Jul 2016
1/*Regardless of the complexity of a conditional, no more than one of 
2the code blocks will be executed.*/
3
4let x = 10;
5let y = 20;
6
7if (x > y) {
8   console.log("x is greater than y");
9} else if (x < y) {
10   console.log("x is less than y");
11} else if (x % 5 === 0) {
12   console.log("x is divisible by 5");
13} else if (x % 2 === 0) {
14   console.log("x is even");
15}
16//x is less than y
17
18/*Even though both of the conditions x % 5 === 0 and x % 2 === 0 
19evaluate to true, neither of the associated code blocks is executed. 
20When a condition is satisfied, the rest of the conditional is 
21skipped.*/
queries leading to this page
5 4 1 if statements5 4 1 if statements