corrections

pull/133/merge
Asabeneh 4 years ago
parent b094b3f64f
commit 97f84bf65f

@ -73,7 +73,7 @@ We agreed that boolean values are either true or false.
### Truthy values ### Truthy values
- All numbers(positive and negative) are truthy except zero - All numbers(positive and negative) are truthy except zero
- All strings are truthy - All strings are truthy except an empty string ('')
- The boolean true - The boolean true
### Falsy values ### Falsy values
@ -616,7 +616,7 @@ console.log(`${date}/${month}/${year} ${hours}:${minutes}`) // 4/1/2020 0:56
1. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years 1. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume some one lives just hundred years
```sh ```sh
Enter number of yours you live: 100 Enter number of years you live: 100
You lived 3153600000 seconds. You lived 3153600000 seconds.
``` ```

@ -108,7 +108,7 @@ const numbers = [1, 2, 3, 4, 5]
const newArr = [] const newArr = []
let sum = 0 let sum = 0
for(let i = 0; i < numbers.length; i++){ for(let i = 0; i < numbers.length; i++){
newArr.push(i * i) newArr.push( numbers[i] ** 2)
} }
@ -406,6 +406,7 @@ for(let i = 0; i <= 5; i++){
['Germany', 'GER', 7], ['Germany', 'GER', 7],
['Hungary', 'HUN', 7], ['Hungary', 'HUN', 7],
['Ireland', 'IRE', 7], ['Ireland', 'IRE', 7],
['Iceland', 'ICE', 7],
['Japan', 'JAP', 5], ['Japan', 'JAP', 5],
['Kenya', 'KEN', 5] ['Kenya', 'KEN', 5]
] ]
@ -414,7 +415,7 @@ for(let i = 0; i <= 5; i++){
2. In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print 'All these countries are without land'. 2. In above countries array, check if there is a country or countries containing the word 'land'. If there are countries containing 'land', print it as array. If there is no country containing the word 'land', print 'All these countries are without land'.
```sh ```sh
['Finland', 'Iceland'] ['Finland','Ireland', 'Iceland']
``` ```
3. In above countries array, check if there is a country or countries end with a substring 'ia'. If there are countries end with, print it as array. If there is no country containing the word 'ai', print 'These are countries ends without ia'. 3. In above countries array, check if there is a country or countries end with a substring 'ia'. If there are countries end with, print it as array. If there is no country containing the word 'ai', print 'These are countries ends without ia'.

@ -502,10 +502,13 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
### Function declaration versus Arrow function ### Function declaration versus Arrow function
It ill be covered in other time It Will be covered in other section.
🌕 You are a rising star, now you knew function . Now, you are super charged with the power of functions. You have just completed day 7 challenges and you are 7 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. 🌕 You are a rising star, now you knew function . Now, you are super charged with the power of functions. You have just completed day 7 challenges and you are 7 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
## Testimony
Now it is time to express your thoughts about the Author and 30DaysOfJavaScript. You can leave your testimonial on this [link](https://testimonify.herokuapp.com/)
## 💻 Exercises ## 💻 Exercises
### Exercises: Level 1 ### Exercises: Level 1
@ -617,7 +620,7 @@ It ill be covered in other time
### Exercises: Level 3 ### Exercises: Level 3
1. Modify question number n . Declare a function name _userIdGeneratedByUser_. It doesnt take any parameter but it takes two inputs using prompt(). One of the input is the number of characters and the second input is the number of ids which are supposed to be generated. 1. Modify the _userIdGenerator_ function. Declare a function name _userIdGeneratedByUser_. It doesnt take any parameter but it takes two inputs using prompt(). One of the input is the number of characters and the second input is the number of ids which are supposed to be generated.
```sh ```sh
userIdGeneratedByUser() userIdGeneratedByUser()

@ -52,7 +52,7 @@ Variables scopes can be:
Variable can be declared globally or locally or window scope. We will see both global and local scope. Variable can be declared globally or locally or window scope. We will see both global and local scope.
Anything declared without let, var or const is scoped at window level. Anything declared without let, var or const is scoped at window level.
Let us image we have a scope.js file. Let us imagine that we have a scope.js file.
### Window Scope ### Window Scope
@ -102,23 +102,25 @@ let a = 'JavaScript' // is a global scope it will be found anywhere in this file
let b = 10 // is a global scope it will be found anywhere in this file let b = 10 // is a global scope it will be found anywhere in this file
function letsLearnScope() { function letsLearnScope() {
console.log(a, b) // JavaScript 10, accessible console.log(a, b) // JavaScript 10, accessible
let c = 30 let value = false
if (true) { if (true) {
// we can access from the function and outside the function but // we can access from the function and outside the function but
// variables declared inside the if will not be accessed outside the if block // variables declared inside the if will not be accessed outside the if block
let a = 'Python' let a = 'Python'
let b = 20 let b = 20
let c = 30
let d = 40 let d = 40
value = !value
console.log(a, b, c) // Python 20 30 console.log(a, b, c) // Python 20 30
} }
// we can not access c because c's scope is only the if block // we can not access c because c's scope is only the if block
console.log(a, b) // JavaScript 10 console.log(a, b, value) // JavaScript 10 true
} }
letsLearnScope() letsLearnScope()
console.log(a, b) // JavaScript 10, accessible console.log(a, b) // JavaScript 10, accessible
``` ```
Now, you have an understanding of scope. A variable declared with *var* only scoped to function but variable declared with *let* or *const* is block scope(function block, if block, loop etc). Block in JavaScript is a code in between two curly brackets ({}). Now, you have an understanding of scope. A variable declared with *var* only scoped to function but variable declared with *let* or *const* is block scope(function block, if block, loop block, etc). Block in JavaScript is a code in between two curly brackets ({}).
```js ```js
//scope.js //scope.js
@ -163,7 +165,7 @@ if (true){
for(let i = 0; i < 3; i++){ for(let i = 0; i < 3; i++){
console.log(i) // 1, 2, 3 console.log(i) // 1, 2, 3
} }
// console.log(i), Uncaught ReferenceError: gravity is not defined // console.log(i), Uncaught ReferenceError: i is not defined
``` ```
@ -432,7 +434,7 @@ console.log(copyPerson.hasOwnProperty('score'))
### Exercises: Level 2 ### Exercises: Level 2
1. Find the person who has many skills in the users object. 1. Find the person who has many skills in the users object.
1. Count logged in users,count users having greater than equal to 50 points from the following object. 1. Count logged in users, count users having greater than equal to 50 points from the following object.
````js ````js
const users = { const users = {

@ -81,23 +81,22 @@ const higherOrder = n => {
} }
return doWhatEver return doWhatEver
} }
return doSomething return doSomething
} }
console.log(higherOrder(2)(3)(10)) console.log(higherOrder(2)(3)(10))
``` ```
Let us see were we use call back functions.For instance the _forEach_ method uses call back. Let us see were we use call back functions. For instance the _forEach_ method uses call back.
```js ```js
const numbers = [1, 2, 3, 4] const numbers = [1, 2, 3, 4]
const sumArray = arr => { const sumArray = arr => {
let sum = 0 let sum = 0
const callBack = function(element) { const callback = function(element) {
sum += element sum += element
} }
numbers.forEach(callback) arr.forEach(callback)
return sum return sum
} }
@ -115,7 +114,7 @@ const numbers = [1, 2, 3, 4]
const sumArray = arr => { const sumArray = arr => {
let sum = 0 let sum = 0
numbers.forEach(function(element) { arr.forEach(function(element) {
sum += element sum += element
}) })
return sum return sum
@ -128,20 +127,20 @@ console.log(sumArray(numbers))
15 15
``` ```
### setting time ### Setting time
In JavaScript we can execute some activity on certain interval of time or we can schedule(wait) for sometime to execute some activities. In JavaScript we can execute some activities in a certain interval of time or we can schedule(wait) for some time to execute some activities.
- setInterval - setInterval
- setTimeout - setTimeout
#### setInterval #### Setting Interaval using a setInterval function
In JavaScript, we use setInterval higher order function to do some activity continuously with in some interval of time. The setInterval global method take a callback function and a duration as a parameter. The duration is in milliseconds and the callback will be always called in that interval of time. In JavaScript, we use setInterval higher order function to do some activity continuously with in some interval of time. The setInterval global method take a callback function and a duration as a parameter. The duration is in milliseconds and the callback will be always called in that interval of time.
```js ```js
// syntax // syntax
function callBack() { function callback() {
// code goes here // code goes here
} }
setInterval(callback, duration) setInterval(callback, duration)
@ -151,10 +150,10 @@ setInterval(callback, duration)
function sayHello() { function sayHello() {
console.log('Hello') console.log('Hello')
} }
setInterval(sayHello, 2000) // it prints hello in every 2 seconds setInterval(sayHello, 1000) // it prints hello in every second, 1000ms is 1s
``` ```
#### setTimeout #### Setting a time using a setTimeout
In JavaScript, we use setTimeout higher order function to execute some action at some time in the future. The setTimeout global method take a callback function and a duration as a parameter. The duration is in milliseconds and the callback wait for that amount of time. In JavaScript, we use setTimeout higher order function to execute some action at some time in the future. The setTimeout global method take a callback function and a duration as a parameter. The duration is in milliseconds and the callback wait for that amount of time.
@ -195,9 +194,8 @@ arr.forEach((element, index, arr) => console.log(index, element, arr))
```js ```js
let sum = 0; let sum = 0;
const numbers = [1,2,3,4,5]; const numbers = [1, 2, 3, 4, 5];
numbers.forEach(num => console.log(num))) numbers.forEach(num => console.log(num))
console.log(sum) console.log(sum)
``` ```
@ -211,8 +209,8 @@ console.log(sum)
```js ```js
let sum = 0; let sum = 0;
const numbers = [1,2,3,4,5]; const numbers = [1, 2, 3, 4, 5];
numbers.forEach(num => sum += num)) numbers.forEach(num => sum += num)
console.log(sum) console.log(sum)
``` ```
@ -349,6 +347,7 @@ console.log(countriesHaveFiveLetters)
```js ```js
const scores = [ const scores = [
{ name: 'Asabeneh', score: 95 }, { name: 'Asabeneh', score: 95 },
{ name: 'Lidiya', score: 98 },
{ name: 'Mathias', score: 80 }, { name: 'Mathias', score: 80 },
{ name: 'Elias', score: 50 }, { name: 'Elias', score: 50 },
{ name: 'Martha', score: 85 }, { name: 'Martha', score: 85 },
@ -360,7 +359,7 @@ console.log(scoresGreaterEight)
``` ```
```sh ```sh
[{name: 'Asabeneh', score: 95}, {name: 'Martha', score: 85},{name: 'John', score: 100}] [{name: 'Asabeneh', score: 95}, { name: 'Lidiya', score: 98 },{name: 'Martha', score: 85},{name: 'John', score: 100}]
``` ```
### reduce ### reduce
@ -391,7 +390,7 @@ _every_: Check if all the elements are similar in one aspect. It returns boolean
```js ```js
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook'] const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
const areAllStr = names.every((name) => typeof name === 'string') const areAllStr = names.every((name) => typeof name === 'string') // Are all strings?
console.log(arrAllStr) console.log(arrAllStr)
``` ```
@ -402,11 +401,9 @@ true
```js ```js
const bools = [true, true, true, true] const bools = [true, true, true, true]
const areAllTrue = bools.every((b) => { const areAllTrue = bools.every((b) => b === true) // Are all true?
return b === true
})
console.log(areAllTrue) //true console.log(areAllTrue) // true
``` ```
```sh ```sh
@ -448,9 +445,7 @@ const scores = [
{ name: 'John', score: 100 }, { name: 'John', score: 100 },
] ]
const score = scores.find((user) => { const score = scores.find((user) => user.score > 80)
return user.score > 80
})
console.log(score) console.log(score)
``` ```
@ -481,15 +476,13 @@ _some_: Check if some of the elements are similar in one aspect. It returns bool
const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook'] const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
const bools = [true, true, true, true] const bools = [true, true, true, true]
const areSomeTrue = bools.some((b) => { const areSomeTrue = bools.some((b) => b === true)
return b === true
})
console.log(areSomeTrue) //true console.log(areSomeTrue) //true
``` ```
```js ```js
const areAllStr = names.some((name) => typeof name === 'number') const areAllStr = names.some((name) => typeof name === 'number') // Are all strings ?
console.log(areAllStr) // false console.log(areAllStr) // false
``` ```
@ -556,7 +549,7 @@ users.sort((a, b) => {
return 0 return 0
}) })
console.log(users) // sorted ascending console.log(users) // sorted ascending
//[{…}, {…}, {…}, {…}] // [{…}, {…}, {…}, {…}]
``` ```
🌕 You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle. 🌕 You are doing great.Never give up because great things take time. You have just completed day 9 challenges and you are 9 steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.

@ -245,7 +245,7 @@ Set(6) {1, 2, 3, 4, 5,6}
### Intersection of sets ### Intersection of sets
To find an intersection of two sets can be achieved using filter. Lets find the union of set A and set B (A ∩ B) To find an intersection of two sets can be achieved using filter. Lets find the intersection of set A and set B (A ∩ B)
```js ```js
let a = [1, 2, 3, 4, 5] let a = [1, 2, 3, 4, 5]
@ -388,8 +388,8 @@ Norway Oslo
### Exercises:Level 1 ### Exercises:Level 1
```js ```js
const a = {4, 5, 8, 9} const a = [4, 5, 8, 9]
const b = {3, 4, 5, 7} const b = [3, 4, 5, 7]
const countries = ['Finland', 'Sweden', 'Norway'] const countries = ['Finland', 'Sweden', 'Norway']
``` ```
@ -432,9 +432,9 @@ const countries = ['Finland', 'Sweden', 'Norway']
// Your output should look like this // Your output should look like this
console.log(mostSpokenLanguages(countries, 3)) console.log(mostSpokenLanguages(countries, 3))
[ [
{'English':91}, {English:91},
{'French':45}, {French:45},
{'Arabic':25} {Arabic:25}
] ]
``` ```

@ -209,7 +209,7 @@ const rectangle = {
height: 10, height: 10,
area: 200 area: 200
} }
let { width: w, heigh: h, area: a, perimeter: p } = rectangle let { width: w, height: h, area: a, perimeter: p } = rectangle
console.log(w, h, a, p) console.log(w, h, a, p)
``` ```
@ -226,7 +226,7 @@ const rectangle = {
height: 10, height: 10,
area: 200 area: 200
} }
let { width, heigh, area, perimeter = 60 } = rectangle let { width, height, area, perimeter = 60 } = rectangle
console.log(width, height, area, perimeter) //20 10 200 60 console.log(width, height, area, perimeter) //20 10 200 60
//Lets modify the object:width to 30 and perimeter to 80 //Lets modify the object:width to 30 and perimeter to 80
@ -239,8 +239,8 @@ const rectangle = {
area: 200, area: 200,
perimeter: 80 perimeter: 80
} }
let { width, heigh, area, perimeter = 60 } = rectangle let { width, height, area, perimeter = 60 } = rectangle
console.log(width, height, area, perimeter) //20 10 200 80 console.log(width, height, area, perimeter) //30 10 200 80
``` ```
Destructuring keys as a function parameters. Lets create a function which take a rectangle object and it return a perimeter of a rectangle. Destructuring keys as a function parameters. Lets create a function which take a rectangle object and it return a perimeter of a rectangle.
@ -695,4 +695,4 @@ const users = [
``` ```
🎉 CONGRATULATIONS ! 🎉 🎉 CONGRATULATIONS ! 🎉
[<< Day 10](../10_Day_Sets_and_Maps/10_day_Sets_and_Maps.md) | [Day 12>>](../12_Day_Regular_expressions/12_day_regular_expressions.md) [<< Day 10](../10_Day_Sets_and_Maps/10_day_Sets_and_Maps.md) | [Day 12 >>](../12_Day_Regular_expressions/12_day_regular_expressions.md)

@ -38,7 +38,7 @@
Web Storage(sessionStorage and localStorage) is a new HTML5 API offering important benefits over traditional cookies. Before HTML5, application data had to be stored in cookies, included in every server request. Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. The data storage limit of cookies in many web browsers is about 4 KB per cookie. We Storages can store far larger data (at least 5MB) and never transferred to the server. All sites from the same or one origin can store and access the same data. Web Storage(sessionStorage and localStorage) is a new HTML5 API offering important benefits over traditional cookies. Before HTML5, application data had to be stored in cookies, included in every server request. Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. The data storage limit of cookies in many web browsers is about 4 KB per cookie. We Storages can store far larger data (at least 5MB) and never transferred to the server. All sites from the same or one origin can store and access the same data.
The data being stored can be accessed using JavaScript, which gives you the ability to leverage client-side scripting to do many things that have traditionally involved server-side programming and relational databases. The are are two Web Storage objects: The data being stored can be accessed using JavaScript, which gives you the ability to leverage client-side scripting to do many things that have traditionally involved server-side programming and relational databases. There are two Web Storage objects:
- sessionStorage - sessionStorage
- localStorage - localStorage

@ -52,7 +52,7 @@ As the Promise.prototype.then() and Promise.prototype.catch() methods return pro
To understand promise very well let us understand callback first. Let's see the following callbacks. From the following code blocks you will notice, the difference between callback and promises. To understand promise very well let us understand callback first. Let's see the following callbacks. From the following code blocks you will notice, the difference between callback and promises.
- call back - call back
Let us see a callback function which can take two parameters. The first parameter is err and the second is result. If the err parameter is false, there will not be error other wise it will return an error. Let us see a callback function which can take two parameters. The first parameter is err and the second is result. If the err parameter is false, there will not be error other wise it will return an error.
In this case the err has a value and it will return the err block. In this case the err has a value and it will return the err block.
@ -73,7 +73,6 @@ const callback = (err, result) => {
} }
doSomething(callback) doSomething(callback)
``` ```
```sh ```sh
@ -106,7 +105,7 @@ doSomething((err, result) => {
### Promise constructor ### Promise constructor
We can create a promise using the Promise constructor. We can create a new promise using the key word new followed by the word Promise and followed by a parenthesis. Inside the parenthesis it it takes a callback function. The promise callback function has two parameters which are the *resolve* and *reject* functions. We can create a promise using the Promise constructor. We can create a new promise using the key word new followed by the word Promise and followed by a parenthesis. Inside the parenthesis it it takes a callback function. The promise callback function has two parameters which are the _resolve_ and _reject_ functions.
```js ```js
// syntax // syntax
@ -134,21 +133,21 @@ doPromise
console.log(result) console.log(result)
}) })
.catch(error => console.log(error)) .catch(error => console.log(error))
``` ```
```sh ```sh
["HTML", "CSS", "JS"] ["HTML", "CSS", "JS"]
``` ```
The above promise has been settled with resolve. The above promise has been settled with resolve.
Let us another example when the promise is settled with reject. Let us another example when the promise is settled with reject.
```js ```js
// Promise // Promise
const doPromise = new Promise((resolve, reject) => { const doPromise = new Promise((resolve, reject) => {
setTimeout(() => { setTimeout(() => {
const skills = ['HTML', 'CSS', 'JS'] const skills = ['HTML', 'CSS', 'JS']
if (skills.indexOf('Node') !== -1) { if (skills.icludes('Node')) {
resolve('fullstack developer') resolve('fullstack developer')
} else { } else {
reject('Something wrong has happened') reject('Something wrong has happened')
@ -160,26 +159,26 @@ doPromise
.then(result => { .then(result => {
console.log(result) console.log(result)
}) })
.catch(error => console.log(error)) .catch(error => console.error(error))
``` ```
```sh ```sh
Something wrong has happened Something wrong has happened
``` ```
## Fetch API ## Fetch API
The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set. In this challenge we will use fetch to request url and APIS. In addition to that let us see demonstrate use case of promises in accessing network resources using the fetch API. The Fetch API provides an interface for fetching resources (including across the network). It will seem familiar to anyone who has used XMLHttpRequest, but the new API provides a more powerful and flexible feature set. In this challenge we will use fetch to request url and APIS. In addition to that let us see demonstrate use case of promises in accessing network resources using the fetch API.
```js ```js
const url = 'https://restcountries.com/v2/all' // countries api const url = 'https://restcountries.com/v2/all' // countries api
fetch(url) fetch(url)
.then(response => response.json()) // accessing the API data as JSON .then(response => response.json()) // accessing the API data as JSON
.then(data => { // getting the data .then(data => {
// getting the data
console.log(data) console.log(data)
}) })
.catch(error => console.log(error)) // handling error if something wrong happens .catch(error => console.error(error)) // handling error if something wrong happens
``` ```
## Async and Await ## Async and Await
@ -198,9 +197,9 @@ square(2)
Promise {<resolved>: 4} Promise {<resolved>: 4}
``` ```
The word *async* in front of a function means that function will return a promise. The above square function instead of a value it returned a promise. The word _async_ in front of a function means that function will return a promise. The above square function instead of a value it returned a promise.
How do we access the value from the promise? To access the value from the promise, we will use the keyword *await*. How do we access the value from the promise? To access the value from the promise, we will use the keyword _await_.
```js ```js
const square = async function (n) { const square = async function (n) {
@ -226,7 +225,7 @@ fetch(url)
.then(data => { .then(data => {
console.log(data) console.log(data)
}) })
.catch(error => console.log(error)) .catch(error => console.error(error))
``` ```
- async and await - async and await
@ -238,7 +237,7 @@ const fetchData = async () => {
const countries = await response.json() const countries = await response.json()
console.log(countries) console.log(countries)
} catch (err) { } catch (err) {
console.log(err) console.error(err)
} }
} }
console.log('===== async and await') console.log('===== async and await')

@ -196,13 +196,13 @@ const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
// iterating an array using regular for loop // iterating an array using regular for loop
let len = names.length; let len = names.length;
for(let i = 0; i < len; i++){ for(let i = 0; i < len; i++){
console.log(names[i].toUpperCas()) console.log(names[i].toUpperCase())
} }
// iterating an array using for of // iterating an array using for of
for( const name of names) { for( const name of names) {
console.log(name.toUpperCase()) console.log(name.toUpperCasee())
} }
// iterating array using forEach // iterating array using forEach

@ -54,6 +54,9 @@
🌕 Your journey to greatness completed successfully. You reached high level of greatness. Now, you are much greater than ever before. I knew what it takes to reach to this level and you made to this point. You are a real hero. Now, it is time to celebrate your success with a friend or with a family. I am looking forward to seeing you in an other challenge. 🌕 Your journey to greatness completed successfully. You reached high level of greatness. Now, you are much greater than ever before. I knew what it takes to reach to this level and you made to this point. You are a real hero. Now, it is time to celebrate your success with a friend or with a family. I am looking forward to seeing you in an other challenge.
## Testimony
Now it is time to express your thoughts about the Author and 30DaysOfJavaScript. You can leave your testimonial on this [link](https://testimonify.herokuapp.com/)
~![Congratulations](./../images/projects/congratulations.gif) ~![Congratulations](./../images/projects/congratulations.gif)
[<< Day 29](../29_Day_Mini_project_animating_characters/29_day_mini_project_animating_characters.md) [<< Day 29](../29_Day_Mini_project_animating_characters/29_day_mini_project_animating_characters.md)

@ -133,7 +133,7 @@ I believe you have the motivation and a strong desire to be a developer, a compu
### Install Node.js ### Install Node.js
You may not need node.js right now but you may need it for later. Install [node.js](https://nodejs.org/en/). You may not need Node.js right now but you may need it for later. Install [node.js](https://nodejs.org/en/).
![Node download](images/download_node.png) ![Node download](images/download_node.png)
@ -148,7 +148,7 @@ asabeneh $ node -v
v12.14.0 v12.14.0
``` ```
When making this tutorial I was using node version 12.14.0, but now the recommended version of node.js for download is 12.17.0. When making this tutorial I was using Node version 12.14.0, but now the recommended version of Node.js for download is v14.17.6.
### Browser ### Browser
@ -156,7 +156,7 @@ There are many browsers out there. However, I strongly recommend Google Chrome.
#### Installing Google Chrome #### Installing Google Chrome
Install [google chrome](https://www.google.com/chrome/) if you do not have one yet. We can write small JavaScript code on the browser console, but we do not use the browser console to develop applications. Install [Google Chrome](https://www.google.com/chrome/) if you do not have one yet. We can write small JavaScript code on the browser console, but we do not use the browser console to develop applications.
![Google Chrome](images/google_chrome.png) ![Google Chrome](images/google_chrome.png)
@ -205,7 +205,7 @@ console.log('Hello, World!')
##### Console.log with Multiple Arguments ##### Console.log with Multiple Arguments
The **console.log()** function can take multiple parameters separated by comma. The syntax looks like as follows:**console.log(param1, param2, param3)** The **console.log()** function can take multiple parameters separated by commas. The syntax looks like as follows:**console.log(param1, param2, param3)**
![console log multiple arguments](./images/console_log_multipl_arguments.png) ![console log multiple arguments](./images/console_log_multipl_arguments.png)
@ -239,7 +239,7 @@ This is a multiline comment
##### Syntax ##### Syntax
Programming languages are similar to human languages. English or many other language uses words, phrases, sentences,compound sentences and other more to convey a meaningful message. The English meaning of syntax is _the arrangement of words and phrases to create well-formed sentences in a language_. The technical definition of syntax is _the structure of statements in a computer language._ Programing languages have syntax. JavaScript is a programming language and like other programming languages it has its own syntax. If we do not write a syntax that JavaScript understands, it will raise different types of errors. We will explore different kinds of JavaScript errors later. For now, let us see syntax errors. Programming languages are similar to human languages. English or many other language uses words, phrases, sentences,compound sentences and other more to convey a meaningful message. The English meaning of syntax is _the arrangement of words and phrases to create well-formed sentences in a language_. The technical definition of syntax is the structure of statements in a computer language.Programming languages have syntax. JavaScript is a programming language and like other programming languages it has its own syntax. If we do not write a syntax that JavaScript understands, it will raise different types of errors. We will explore different kinds of JavaScript errors later. For now, let us see syntax errors.
![Error](images/raising_syntax_error.png) ![Error](images/raising_syntax_error.png)
@ -255,7 +255,7 @@ So far, we saw how to display text using the _console.log()_. If we are printing
```js ```js
console.log('Hello, World!') console.log('Hello, World!')
console.log('Hello, World!') console.log("Hello, World!")
console.log(`Hello, World!`) console.log(`Hello, World!`)
``` ```
@ -377,7 +377,7 @@ Open the browser console to see the output from the console.log()
### External Script ### External Script
Similar to the internal script, the external script link can be on the header or body, but it is preferred to put it in the body. Similar to the internal script, the external script link can be on the header or body, but it is preferred to put it in the body.
First, we should create an external JavaScript file with .js extension. All files ending with .js extension. All files ending with .js extension are JavaScript files. Create a file named introduction.js inside your project directory and write the following code and link this .js file at the bottom of the body. First, we should create an external JavaScript file with .js extension. All files ending with .js extension are JavaScript files. Create a file named introduction.js inside your project directory and write the following code and link this .js file at the bottom of the body.
```js ```js
console.log('Welcome to 30DaysOfJavaScript') console.log('Welcome to 30DaysOfJavaScript')
@ -405,8 +405,8 @@ External scripts in the _body_:
<title>30DaysOfJavaScript:External script</title> <title>30DaysOfJavaScript:External script</title>
</head> </head>
<body> <body>
//it could be in the header or in the body // Here is the recommended place <!-- it could be in the header or in the body -->
to put the external script <!-- Here is the recommended place to put the external script -->
<script src="introduction.js"></script> <script src="introduction.js"></script>
</body> </body>
</html> </html>
@ -463,21 +463,22 @@ A collection of one or more characters between two single quotes, double quotes,
'Finland' 'Finland'
'JavaScript is a beautiful programming language' 'JavaScript is a beautiful programming language'
'I love teaching' 'I love teaching'
'I hope you are enjoying the first day'`We can also create a string using a backtick` 'I hope you are enjoying the first day'
;('A string could be just as small as one character as big as many pages') `We can also create a string using a backtick`
'A string could be just as small as one character as big as many pages'
``` ```
### Booleans ### Booleans
A boolean value is either True or False. Any comparisons return a boolean value, which is either true or false. A boolean value is either True or False. Any comparisons returns a boolean value, which is either true or false.
A boolean data type is either a true or false value. A boolean data type is either a true or false value.
**Example:** **Example:**
```js ```js
true // if the light on ,the value is true true // if the light is on, the value is true
false // if the light off, the value is false false // if the light is off, the value is false
``` ```
### Undefined ### Undefined
@ -486,7 +487,7 @@ In JavaScript, if we don't assign a value to a variable, the value is undefined.
```js ```js
let firstName let firstName
console.log(firstName) //not defined, because it is not assigned to a value yet console.log(firstName) // undefined, because it is not assigned to a value yet
``` ```
### Null ### Null
@ -531,6 +532,7 @@ Multiline commenting:
let age = 100; let age = 100;
let isMarried = true; let isMarried = true;
This is a Multiple line comment This is a Multiple line comment
*/ */
``` ```

Loading…
Cancel
Save