You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 04_Day_Conditionals/04_day_conditionals.md
+28-25
Original file line number
Diff line number
Diff line change
@@ -19,9 +19,9 @@
19
19
20
20
-[📔 Day 4](#-day-4)
21
21
-[Conditionals](#conditionals)
22
-
-[if](#if)
23
-
-[if else](#if-else)
24
-
-[if else if else](#if-else-if-else)
22
+
-[If](#if)
23
+
-[If Else](#if-else)
24
+
-[If Else if Else](#if-else-if-else)
25
25
-[Switch](#switch)
26
26
-[Ternary Operators](#ternary-operators)
27
27
-[💻 Exercises](#-exercises)
@@ -33,11 +33,11 @@
33
33
34
34
## Conditionals
35
35
36
-
Conditional statements are used to make decisions based on different conditions.
36
+
Conditional statements are used for make decisions based on different conditions.
37
37
By default , statements in JavaScript script executed sequentially from top to bottom. If the processing logic require so, the sequential flow of execution can be altered in two ways:
38
38
39
39
- Conditional execution: a block of one or more statements will be executed if a certain expression is true
40
-
- Repetitive execution: a block of one or more statements will be repetitively executed as long as a certain expression is true. In this section, we will cover _if_, _else_ , _else if_ statements. The comparison and logical operator we learned in the previous sections will be useful in here.
40
+
- Repetitive execution: a block of one or more statements will be repetitively executed as long as a certain expression is true. In this section, we will cover _if_, _else_ , _else if_ statements. The comparison and logical operators we learned in the previous sections will be useful in here.
41
41
42
42
Conditions can be implementing using the following ways:
43
43
@@ -47,14 +47,14 @@ Conditions can be implementing using the following ways:
47
47
- switch
48
48
- ternary operator
49
49
50
-
### if
50
+
### If
51
51
52
-
In JavaScript and other programming languages the key word _if_ is used to check if a condition is true and to execute the block code. To create an if condition, we need _if_ keyword, condition inside a parenthesis and block of code inside a curly bracket({}).
52
+
In JavaScript and other programming languages the key word _if_ is to used check if a condition is true and to execute the block code. To create an if condition, we need _if_ keyword, condition inside a parenthesis and block of code inside a curly bracket({}).
53
53
54
54
```js
55
55
// syntax
56
56
if (condition) {
57
-
//this part of code run for truthy condition
57
+
//this part of code runs for truthy condition
58
58
}
59
59
```
60
60
@@ -68,7 +68,7 @@ if (num > 0) {
68
68
// 3 is a positive number
69
69
```
70
70
71
-
As you can see in the above condition, 3 is greater than 0 and it is a positive number. The condition was true and the block code was executed. However, if the condition is false, we do not see a result.
71
+
As you can see in the condition example above, 3 is greater than 0, so it is a positive number. The condition was true and the block of code was executed. However, if the condition is false, we won't see any results.
72
72
73
73
```js
74
74
let isRaining =true
@@ -77,18 +77,18 @@ if (isRaining) {
77
77
}
78
78
```
79
79
80
-
The same goes for the second condition, if isRaining is false the if block will not be executed and we do not see an output. In order to see the result of the falsy condition, we should have another block, which is going to be _else_.
80
+
The same goes for the second condition, if isRaining is false the if block will not be executed and we do not see any output. In order to see the result of a falsy condition, we should have another block, which is going to be _else_.
81
81
82
-
### if else
82
+
### If Else
83
83
84
84
If condition is true the first block will be executed, if not the else condition will be executed.
85
85
86
86
```js
87
87
// syntax
88
88
if (condition) {
89
-
// this part of code run for truthy condition
89
+
// this part of code runs for truthy condition
90
90
} else {
91
-
// this part of code run for false condition
91
+
// this part of code runs for false condition
92
92
}
93
93
```
94
94
@@ -128,11 +128,11 @@ if (isRaining) {
128
128
// No need for a rain coat.
129
129
```
130
130
131
-
The above condition is false, therefore the else block was executed. How about if our condition is more than two, we will use *else if* conditions.
131
+
The last condition is false, therefore the else block was executed. What if we have more than two conditions? In that case, we would use *else if* conditions.
132
132
133
-
### if else if else
133
+
### If Else if Else
134
134
135
-
On our daily life, we make decision on daily basis. We make decision not by checking one or two conditions instead we make decisions based on multiple conditions. As similar to our daily life, programming is also full of conditions. We use *else if* when we have multiple conditions.
135
+
On our daily life, we make decisions on daily basis. We make decisions not by checking one or two conditions instead we make decisions based on multiple conditions. As similar to our daily life, programming is also full of conditions. We use *else if* when we have multiple conditions.
136
136
137
137
```js
138
138
// syntax
@@ -178,7 +178,7 @@ if (weather === 'rainy') {
178
178
### Switch
179
179
180
180
Switch is an alternative for **if else if else else**.
181
-
The switch statement starts with a switch keyword followed by a parenthesis and code block. Inside the code block we will have different cases. Case block run if the value in the switch statement parenthesis match with the case vale. The break is to terminate and it does not go down after the condition is satisfied. The default block run if all the cases don't satisfy the condition.
181
+
The switch statement starts with a *switch* keyword followed by a parenthesis and code block. Inside the code block we will have different cases. Case block runs if the value in the switch statement parenthesis matches with the case value. The break statement is to terminate execution so the code execution does not go down after the condition is satisfied. The default block runs if all the cases don't satisfy the condition.
182
182
183
183
```js
184
184
switch(caseValue){
@@ -264,7 +264,7 @@ switch (true) {
264
264
265
265
### Ternary Operators
266
266
267
-
Another way to write conditionals is using ternary operators. We have covered this in other sections but we should also mention it here.
267
+
Another way to write conditionals is using ternary operators. We have covered this in other sections, but we should also mention it here.
268
268
269
269
```js
270
270
let isRaining =true
@@ -273,13 +273,13 @@ isRaining
273
273
:console.log('No need for a rain coat.')
274
274
```
275
275
276
-
🌕 You are extraordinary and you have a remarkable potential. You have just completed day 4 challenges and you are four steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
276
+
🌕 You are extraordinary and you have a remarkable potential. You have just completed day 4 challenges and you are four steps ahead to your way to greatness. Now do some exercises for your brain and muscle.
277
277
278
278
## 💻 Exercises
279
279
280
280
### Exercises: Level 1
281
281
282
-
1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:You are old enough to drive but if not 18 give feedback to wait for the years he supposed to wait for.
282
+
1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he neds to turn 18.
283
283
284
284
```sh
285
285
Enter your age: 30
@@ -289,14 +289,14 @@ isRaining
289
289
You are left with 3 years to drive.
290
290
```
291
291
292
-
1. Compare the values of myAge and yourAge using if … else. Based on the comparison log to console who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.
292
+
1. Compare the values of myAge and yourAge using if … else. Based on the comparison and log the result to console stating who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.
293
293
294
294
```sh
295
295
Enter your age: 30
296
296
You are 5 years older than me.
297
297
```
298
298
299
-
1. If a is greater than b return 'a is greater than b' else 'a is less than b'. Try to implement in to ways
299
+
1. If a is greater than b return 'a is greater than b' else 'a is less than b'. Try to implement it in to ways
300
300
301
301
- using if else
302
302
- ternary operator.
@@ -310,7 +310,7 @@ isRaining
310
310
4 is greater than 3
311
311
```
312
312
313
-
1. Even numbers are divisible by 2 and the remainder is zero. Howdo you check if a number is even or not using JavaScript?
313
+
1. Even numbers are divisible by 2 and the remainder is zero. Howdo you check,if a number is even or not using JavaScript?
314
314
315
315
```sh
316
316
Enter a number: 2
@@ -322,14 +322,14 @@ isRaining
322
322
323
323
### Exercises: Level 2
324
324
325
-
1. Write a code which can give grade to students according to theirs scores:
325
+
1. Write a code which can give grades to students according to theirs scores:
326
326
-80-100, A
327
327
-70-89, B
328
328
-60-69, C
329
329
-50-59, D
330
330
-0-49, F
331
331
1. Check if the season is Autumn, Winter, Spring or Summer.
332
-
If the user input is:
332
+
If the user input is:
333
333
- September, October or November, the season is Autumn.
334
334
- December, January or February, the season is Winter.
335
335
- March, April or May, the season is Spring
@@ -368,6 +368,9 @@ isRaining
368
368
February has 28 days.
369
369
```
370
370
371
+
1. Write a program which tells the number of days in a month, now consider leap year.
372
+
373
+
371
374
🎉 CONGRATULATIONS! 🎉
372
375
373
376
[<< Day 3](../03_Day_Booleans_operators_date/03_booleans_operators_date.md) | [Day 5>>](../05_Day_Arrays/05_day_arrays.md)
Copy file name to clipboardExpand all lines: readMe.md
+3-3
Original file line number
Diff line number
Diff line change
@@ -72,7 +72,7 @@
72
72

73
73
74
74
-[30 Days Of JavaScript](#30-days-of-javascript)
75
-
-[📔Day 1](#day-1)
75
+
-[📔Day 1](#-day-1)
76
76
-[Introduction](#introduction)
77
77
-[Requirements](#requirements)
78
78
-[Setup](#setup)
@@ -105,13 +105,13 @@
105
105
-[Variables](#variables)
106
106
-[💻 Day 1: Exercises](#-day-1-exercises)
107
107
108
-
# 📔Day 1
108
+
# 📔Day 1
109
109
110
110
## Introduction
111
111
112
112
**Congratulations** on deciding to participate in 30 days of JavaScript programming challenge. In this challenge you will learn everything you need to be a JavaScript programmer, and in general, the whole concept of programming. In the end of the challenge you will get a 30DaysOfJavaScript programming challenge completion certificate. In case you need help or if you would like to help others you may join the [telegram group](https://t.me/ThirtyDaysOfJavaScript).
113
113
114
-
**A 30DaysOfJavaScript** challenge is a guide for both beginners and advanced JavaScript developers. Welcome to JavaScript.JavaScript is the language of the web. I enjoy using and teaching JavaScript and I hope you will do so too.
114
+
**A 30DaysOfJavaScript** challenge is a guide for both beginners and advanced JavaScript developers. Welcome to JavaScript.JavaScript is the language of the web. I enjoy using and teaching JavaScript and I hope you will do so too.
115
115
116
116
In this step by step JavaScript challenge, you will learn JavaScript, the most popular programming language in the history of mankind.
117
117
JavaScript is used **_to add interactivity to websites, to develop mobile apps, desktop applications, games_** and nowadays JavaScript can be used for **_machine learning_** and **_AI_**.
0 commit comments