Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Asabeneh committed Sep 6, 2020
1 parent c205c28 commit ff64df9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 29 deletions.
53 changes: 28 additions & 25 deletions 04_Day_Conditionals/04_day_conditionals.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@

- [📔 Day 4](#-day-4)
- [Conditionals](#conditionals)
- [if](#if)
- [if else](#if-else)
- [if else if else](#if-else-if-else)
- [If](#if)
- [If Else](#if-else)
- [If Else if Else](#if-else-if-else)
- [Switch](#switch)
- [Ternary Operators](#ternary-operators)
- [💻 Exercises](#-exercises)
Expand All @@ -33,11 +33,11 @@

## Conditionals

Conditional statements are used to make decisions based on different conditions.
Conditional statements are used for make decisions based on different conditions.
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:

- Conditional execution: a block of one or more statements will be executed if a certain expression is true
- 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.
- 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.

Conditions can be implementing using the following ways:

Expand All @@ -47,14 +47,14 @@ Conditions can be implementing using the following ways:
- switch
- ternary operator

### if
### If

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({}).
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({}).

```js
// syntax
if (condition) {
//this part of code run for truthy condition
//this part of code runs for truthy condition
}
```

Expand All @@ -68,7 +68,7 @@ if (num > 0) {
// 3 is a positive number
```

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.
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.

```js
let isRaining = true
Expand All @@ -77,18 +77,18 @@ if (isRaining) {
}
```

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_.
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_.

### if else
### If Else

If condition is true the first block will be executed, if not the else condition will be executed.

```js
// syntax
if (condition) {
// this part of code run for truthy condition
// this part of code runs for truthy condition
} else {
// this part of code run for false condition
// this part of code runs for false condition
}
```

Expand Down Expand Up @@ -128,11 +128,11 @@ if (isRaining) {
// No need for a rain coat.
```

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.
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.

### if else if else
### If Else if Else

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.
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.

```js
// syntax
Expand Down Expand Up @@ -178,7 +178,7 @@ if (weather === 'rainy') {
### Switch

Switch is an alternative for **if else if else else**.
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.
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.

```js
switch(caseValue){
Expand Down Expand Up @@ -264,7 +264,7 @@ switch (true) {

### Ternary Operators

Another way to write conditionals is using ternary operators. We have covered this in other sections but we should also mention it here.
Another way to write conditionals is using ternary operators. We have covered this in other sections, but we should also mention it here.

```js
let isRaining = true
Expand All @@ -273,13 +273,13 @@ isRaining
: console.log('No need for a rain coat.')
```

🌕 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.
🌕 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.

## 💻 Exercises

### Exercises: Level 1

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.
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.

```sh
Enter your age: 30
Expand All @@ -289,14 +289,14 @@ isRaining
You are left with 3 years to drive.
```

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.
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.

```sh
Enter your age: 30
You are 5 years older than me.
```

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
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

- using if else
- ternary operator.
Expand All @@ -310,7 +310,7 @@ isRaining
4 is greater than 3
```

1. Even numbers are divisible by 2 and the remainder is zero. How do you check if a number is even or not using JavaScript?
1. Even numbers are divisible by 2 and the remainder is zero. How do you check, if a number is even or not using JavaScript?

```sh
Enter a number: 2
Expand All @@ -322,14 +322,14 @@ isRaining

### Exercises: Level 2

1. Write a code which can give grade to students according to theirs scores:
1. Write a code which can give grades to students according to theirs scores:
- 80-100, A
- 70-89, B
- 60-69, C
- 50-59, D
- 0-49, F
1. Check if the season is Autumn, Winter, Spring or Summer.
If the user input is:
If the user input is :
- September, October or November, the season is Autumn.
- December, January or February, the season is Winter.
- March, April or May, the season is Spring
Expand Down Expand Up @@ -368,6 +368,9 @@ isRaining
February has 28 days.
```

1. Write a program which tells the number of days in a month, now consider leap year.


🎉 CONGRATULATIONS ! 🎉

[<< Day 3](../03_Day_Booleans_operators_date/03_booleans_operators_date.md) | [Day 5 >>](../05_Day_Arrays/05_day_arrays.md)
2 changes: 1 addition & 1 deletion 10_Day_Sets_and_Maps/10_day_Sets_and_Maps.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

## Set

Set is a collection a collection of elements. Set can only contains unique elements.
Set is a collection of elements. Set can only contains unique elements.
Lets see how to create a set

### Creating an empty set
Expand Down
6 changes: 3 additions & 3 deletions readMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
![Thirty Days Of JavaScript](./images/day_1_1.png)

- [30 Days Of JavaScript](#30-days-of-javascript)
- [📔Day 1](#day-1)
- [📔 Day 1](#-day-1)
- [Introduction](#introduction)
- [Requirements](#requirements)
- [Setup](#setup)
Expand Down Expand Up @@ -105,13 +105,13 @@
- [Variables](#variables)
- [💻 Day 1: Exercises](#-day-1-exercises)

# 📔Day 1
# 📔 Day 1

## Introduction

**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).

**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.
**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.

In this step by step JavaScript challenge, you will learn JavaScript, the most popular programming language in the history of mankind.
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_**.
Expand Down

0 comments on commit ff64df9

Please sign in to comment.