Skip to content

Commit 5521bba

Browse files
01comments and 02logic-&-conditions files are added
1 parent 684f66b commit 5521bba

File tree

2 files changed

+153
-0
lines changed

2 files changed

+153
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
// 019. JS Comments
3+
4+
// The JavaScript comments are meaningful way to deliver message.
5+
// It is used to add information about the code, warnings or suggestions so that end user can easily interpret the code.
6+
7+
// There are two types of comments in JavaScript.
8+
9+
// Single-line Comment (keyboard shortcut --> Ctrl + /)
10+
11+
/* Multi-line Comment (keyboard shortcut --> Shift + Alt + A)
12+
line 2
13+
line 3
14+
line 4 */
15+
16+
/*
17+
Advantages of JavaScript comments
18+
To make code easy to understand
19+
To avoid the unnecessary code
20+
*/
21+
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
2+
// 20. JS Logic & Conditions
3+
4+
/*
5+
There are four options
6+
1. if condition
7+
2. else condition
8+
3. else if condition
9+
4. switch statement
10+
*/
11+
12+
// 21. JS If condition
13+
14+
// Conditional Operator
15+
16+
var a = 30
17+
var b = 200
18+
19+
// a > b true false
20+
// if (condition) {
21+
// // code
22+
// }
23+
24+
if (a > b) {
25+
console.log(a + ' is greater than ' + b)
26+
}
27+
28+
if (a < b) {
29+
console.log(b + ' is greater than ' + a);
30+
}
31+
32+
var n = 50
33+
34+
if (n%2 == 0) {
35+
console.log(n + ' is Even Number')
36+
}
37+
38+
if (n%2 == 1) {
39+
console.log(n + ' is Odd Number')
40+
}
41+
42+
// 22. JS Else Condition
43+
44+
a = 10
45+
b = 20
46+
47+
if (a > b) {
48+
console.log('A is greater than B')
49+
}
50+
else {
51+
console.log('B is greater than A');
52+
}
53+
54+
n = 50
55+
56+
if (n%2 == 0) {
57+
console.log(n + ' is Even Number')
58+
}
59+
else {
60+
console.log(n + ' is Odd Number')
61+
}
62+
63+
64+
// 23. JS Else If condition
65+
66+
a = 20
67+
b = 20
68+
69+
if (a > b) {
70+
console.log('A is greater than B')
71+
}
72+
else if (a < b) {
73+
console.log('B is greater than A');
74+
}
75+
else {
76+
console.log('They both are same number')
77+
}
78+
79+
n = 1
80+
81+
if (n == 0) {
82+
console.log(n + ' is zero')
83+
}
84+
else if (n%2 == 0) {
85+
console.log(n + ' is Even Number')
86+
}
87+
else {
88+
console.log(n + ' is Odd Number')
89+
}
90+
91+
92+
// 24. JS Switch Statement
93+
94+
var date = new Date()
95+
96+
// 0 - Sunday, 1 - Monday, 2 - Tuesday
97+
// date.getDay() --> return current day
98+
var today = date.getDay()
99+
100+
// switch (today) {
101+
switch (8) {
102+
case 0:
103+
console.log('Today is Sunday')
104+
break
105+
106+
case 1:
107+
console.log('Today is Monday')
108+
break
109+
110+
case 2:
111+
console.log('Today is Tuesday')
112+
break
113+
114+
case 3:
115+
console.log('Today is Wednesday')
116+
break
117+
118+
case 4:
119+
console.log('Today is Thursday')
120+
break
121+
122+
case 5:
123+
console.log('Today is Friday')
124+
break
125+
126+
case 6:
127+
console.log('Today is Saturday')
128+
break
129+
default:
130+
console.log('Not a Valid Number')
131+
}
132+

0 commit comments

Comments
 (0)