some cleaning

pull/21/head
Asabeneh 5 years ago
parent b6a158d0e9
commit 48ad1d6cf5

@ -9,7 +9,7 @@
- [Conditionals](#conditionals) - [Conditionals](#conditionals)
- [if](#if) - [if](#if)
- [if else](#if-else) - [if else](#if-else)
- [if else if else](#if-else-if-else) - [if else if else else](#if-else-if-else-else)
- [Switch](#switch) - [Switch](#switch)
- [Ternary Operators](#ternary-operators) - [Ternary Operators](#ternary-operators)
- [💻 Exercise : Conditionals](#%f0%9f%92%bb-exercise--conditionals) - [💻 Exercise : Conditionals](#%f0%9f%92%bb-exercise--conditionals)
@ -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. 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 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. 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.

@ -129,15 +129,18 @@ As we have seen in earlier section, we can split a string at different position
```js ```js
let js = 'JavaScript' let js = 'JavaScript'
const charsInJavaScript = js.split('') // ["J", "a", "v", "a", "S", "c", "r", "i", "p", "t"] const charsInJavaScript = js.split('')
console.log(charsInJavaScript)
console.log(charsInJavaScript) // ["J", "a", "v", "a", "S", "c", "r", "i", "p", "t"]
let companiesString = 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' let companiesString = 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon'
const companies = companiesString.split(',') const companies = companiesString.split(',')
console.log(companies) // ["Facebook", " Google", " Microsoft", " Apple", " IBM", " Oracle", " Amazon"] console.log(companies) // ["Facebook", " Google", " Microsoft", " Apple", " IBM", " Oracle", " Amazon"]
let text = let text =
'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.'
const words = text.split(' ') const words = text.split(' ')
console.log(words) console.log(words)
// the text has special characters think how you can just get only the words // the text has special characters think how you can just get only the words
// ["I", "love", "teaching", "and", "empowering", "people.", "I", "teach", "HTML,", "CSS,", "JS,", "React,", "Python"] // ["I", "love", "teaching", "and", "empowering", "people.", "I", "teach", "HTML,", "CSS,", "JS,", "React,", "Python"]
@ -152,14 +155,19 @@ We access each element in an array using their index. An array index start from
```js ```js
const fruits = ['banana', 'orange', 'mango', 'lemon'] const fruits = ['banana', 'orange', 'mango', 'lemon']
let firstFruit = fruits[0] // we are accessing the first item using its index let firstFruit = fruits[0] // we are accessing the first item using its index
console.log(firstFruit) // banana console.log(firstFruit) // banana
secondFruit = fruits[1] secondFruit = fruits[1]
console.log(secondFruit) // orange console.log(secondFruit) // orange
lastFruit = fruits[3]
let lastFruit = fruits[3]
console.log(lastFruit) // lemon console.log(lastFruit) // lemon
// Last index // Last index can be calculated as follows
let lastIndex = len(fruits) - 1 let lastIndex = len(fruits) - 1
let lastFruit = fruits[lastIndex] lastFruit = fruits[lastIndex]
console.log(lastFruit) // lemon
``` ```
```js ```js
@ -258,11 +266,11 @@ const countries = [
'Ireland', 'Ireland',
'Japan', 'Japan',
'Kenya' 'Kenya'
] ]
countries[0] = 'Afghanistan' // Albania replaced by Afghanistan countries[0] = 'Afghanistan' // Replacing Albania by Afghanistan
let lastIndex = countries.length - 1 let lastIndex = countries.length - 1
countries[lastIndex] = 'Korea' countries[lastIndex] = 'Korea' // Replacing Kenya by Korea
console.log(countries) console.log(countries)
``` ```

Loading…
Cancel
Save