1If - Else Statements
2if (condition) {
3// what to do if condition is met
4} else {
5// what to do if condition is not met
6}
7
1if (time < 10) {
2 greeting = "Good morning";
3} else if (time < 20) {
4 greeting = "Good day";
5} else {
6 greeting = "Good evening";
7}
1var age=20;
2if (age < 18) {
3 console.log("underage");
4} else {
5 console.log("let em in!");
6}
1if (expression 1) {
2 Statement(s) to be executed if expression 1 is true
3} else if (expression 2) {
4 Statement(s) to be executed if expression 2 is true
5} else if (expression 3) {
6 Statement(s) to be executed if expression 3 is true
7} else {
8 Statement(s) to be executed if no expression is true
9}
10
1if (5 < 10) {
2 console.log("5 is less than 10");
3} else {
4 console.log("5 is now bigger than 10")
5}
1if (pros < 10) {
2 console.log("LESS THAN 10 PROS!");
3}
4else if (pros < 5) {
5 console.log("LESS THAN 5 PROS!");
6}
7else {
8 console.log("How many pros are there?");
9}