From 48ad1d6cf5b5717a427a54b1e5189ad1a8685efb Mon Sep 17 00:00:00 2001 From: Asabeneh Date: Mon, 6 Jan 2020 04:02:20 +0200 Subject: [PATCH] some cleaning --- 04_Day/04_day_conditionals.md | 4 ++-- 05_Day/05_day_arrays.md | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/04_Day/04_day_conditionals.md b/04_Day/04_day_conditionals.md index c070883a..624505a2 100644 --- a/04_Day/04_day_conditionals.md +++ b/04_Day/04_day_conditionals.md @@ -9,7 +9,7 @@ - [Conditionals](#conditionals) - [if](#if) - [if else](#if-else) - - [if else if else](#if-else-if-else) + - [if else if else else](#if-else-if-else-else) - [Switch](#switch) - [Ternary Operators](#ternary-operators) - [💻 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. -### 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. diff --git a/05_Day/05_day_arrays.md b/05_Day/05_day_arrays.md index a8043bb9..18b2c480 100644 --- a/05_Day/05_day_arrays.md +++ b/05_Day/05_day_arrays.md @@ -129,15 +129,18 @@ As we have seen in earlier section, we can split a string at different position ```js let js = 'JavaScript' -const charsInJavaScript = js.split('') // ["J", "a", "v", "a", "S", "c", "r", "i", "p", "t"] -console.log(charsInJavaScript) +const charsInJavaScript = js.split('') + +console.log(charsInJavaScript) // ["J", "a", "v", "a", "S", "c", "r", "i", "p", "t"] let companiesString = 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' const companies = companiesString.split(',') + console.log(companies) // ["Facebook", " Google", " Microsoft", " Apple", " IBM", " Oracle", " Amazon"] let text = 'I love teaching and empowering people. I teach HTML, CSS, JS, React, Python.' const words = text.split(' ') + console.log(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"] @@ -152,14 +155,19 @@ We access each element in an array using their index. An array index start from ```js const fruits = ['banana', 'orange', 'mango', 'lemon'] let firstFruit = fruits[0] // we are accessing the first item using its index + console.log(firstFruit) // banana + secondFruit = fruits[1] console.log(secondFruit) // orange -lastFruit = fruits[3] + +let lastFruit = fruits[3] console.log(lastFruit) // lemon -// Last index +// Last index can be calculated as follows + let lastIndex = len(fruits) - 1 -let lastFruit = fruits[lastIndex] +lastFruit = fruits[lastIndex] +console.log(lastFruit) // lemon ``` ```js @@ -258,11 +266,11 @@ const countries = [ 'Ireland', 'Japan', 'Kenya' -] +] -countries[0] = 'Afghanistan' // Albania replaced by Afghanistan +countries[0] = 'Afghanistan' // Replacing Albania by Afghanistan let lastIndex = countries.length - 1 -countries[lastIndex] = 'Korea' +countries[lastIndex] = 'Korea' // Replacing Kenya by Korea console.log(countries) ```