File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Path: src/01-intro/03-conditionals.js
2
+
3
+ /* Example 01 - if-else */
4
+ let number = 0 ;
5
+ if ( number === 1 ) {
6
+ console . log ( 'number is equal to 1' ) ;
7
+ } else {
8
+ console . log ( 'number is not equal to 1, the value of number is ' + number ) ;
9
+ }
10
+
11
+ /* Example 02 - ternary operator - if..else */
12
+ if ( number === 1 ) {
13
+ number -- ;
14
+ } else {
15
+ number ++ ;
16
+ }
17
+
18
+ // is the same as
19
+ number === 1 ? number -- : number ++ ;
20
+
21
+ /* Example 03 - if-else-if-else... */
22
+ let month = 5 ;
23
+ if ( month === 1 ) {
24
+ console . log ( 'January' ) ;
25
+ } else if ( month === 2 ) {
26
+ console . log ( 'February' ) ;
27
+ } else if ( month === 3 ) {
28
+ console . log ( 'March' ) ;
29
+ } else {
30
+ console . log ( 'Month is not January, February or March' ) ;
31
+ }
32
+
33
+ /* Example 05 - switch */
34
+ switch ( month ) {
35
+ case 1 :
36
+ console . log ( 'January' ) ;
37
+ break ;
38
+ case 2 :
39
+ console . log ( 'February' ) ;
40
+ break ;
41
+ case 3 :
42
+ console . log ( 'March' ) ;
43
+ break ;
44
+ default :
45
+ console . log ( 'Month is not January, February or March' ) ;
46
+ }
47
+
48
+ // to see the output of this file use the command: node src/01-intro/03-conditionals.js
You can’t perform that action at this time.
0 commit comments