From fc0b62b7f68b8d42943373ae039b22a24e032747 Mon Sep 17 00:00:00 2001 From: Asabeneh Date: Sun, 5 Jan 2020 16:02:08 +0200 Subject: [PATCH] some fixes --- 03_Day/03_booleans_operators_date.md | 8 ++++--- 04_Day/04_day_conditionals.md | 34 ++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/03_Day/03_booleans_operators_date.md b/03_Day/03_booleans_operators_date.md index 486b8104..91989ea9 100644 --- a/03_Day/03_booleans_operators_date.md +++ b/03_Day/03_booleans_operators_date.md @@ -17,7 +17,7 @@ - [Logical Operators](#logical-operators) - [Increment Operator](#increment-operator) - [Decrement Operator](#decrement-operator) - - [Ternary Operators](#ternary-operators) + - [Ternary Operators](#ternary-operators) - [Operator Precendence](#operator-precendence) - [Window Methods](#window-methods) - [Window alert() method](#window-alert-method) @@ -204,7 +204,9 @@ console.log('python'.length > 'dragon'.length) // false ``` Try to understand the above comparisons with some logic. Remember without any logic might be difficult. -JavaScript is some how a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types. +JavaScript is some how a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result. + +As rule of thumb, if a value is not true with == it will not be equall with ===. Using === is safer than using ===. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types. ### Logical Operators @@ -278,7 +280,7 @@ console.log(count--) // 0 console.log(count) // -1 ``` -#### Ternary Operators +### Ternary Operators Ternary operator allows to write a condition. Another way to write conditionals is using ternary operators. Look at the following examples: diff --git a/04_Day/04_day_conditionals.md b/04_Day/04_day_conditionals.md index 82d6a7a7..8a76a332 100644 --- a/04_Day/04_day_conditionals.md +++ b/04_Day/04_day_conditionals.md @@ -1,15 +1,15 @@ ## Table of Contents -[<< Day 3](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/03_Day/03_day_booleans_operators_date.md) | [Day 5 >>](#) +[<< Day 3](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/03_Day/03_booleans_operators_date.md) | [Day 5 >>](#) -- ![Thirty Days Of JavaScript](./day_1_4.png) - [📔 Day 4](#%f0%9f%93%94-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) - [💻 Exercise - 8 : Conditionals](#%f0%9f%92%bb-exercise---8--conditionals) @@ -32,7 +32,7 @@ Conditions can be implementing using the following ways: - switch - ternary operator -### If +### if In JavaScript and other programming languages the key word _if_ use 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({}). @@ -62,7 +62,7 @@ if (isRaining) { 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. 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_. -### If Else +### if else If condition is true the first block will be executed, if not the else condition will be executed. @@ -113,7 +113,7 @@ if (isRaining) { 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. -### 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 conditions. We use *else if* when we have multiple conditions. @@ -160,7 +160,23 @@ if (weather === 'rainy') { ### Switch -Switch is an alternative for **if else if else else** +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. + +```js +switch(caseValue){ + case 1: + // code + break + case 2: + // code + break + case 3: + // code + default: + // code +} +``` ```js let weather = 'cloudy' @@ -309,4 +325,4 @@ isRaining 🎉 CONGRATULATIONS ! 🎉 -[<< Day 3](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/03_Day/03_day_booleans_operators_date.md) | [Day 5 >>](#) +[<< Day 3](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/03_Day/03_booleans_operators_date.md) | [Day 5 >>](#) \ No newline at end of file