corrections

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

@ -73,7 +73,7 @@ We agreed that boolean values are either true or false.
### Truthy values
- All numbers(positive and negative) are truthy except zero
- All strings are truthy
- All strings are truthy except an empty string ('')
- The boolean true
### 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
```sh
Enter number of yours you live: 100
Enter number of years you live: 100
You lived 3153600000 seconds.
```

@ -108,7 +108,7 @@ const numbers = [1, 2, 3, 4, 5]
const newArr = []
let sum = 0
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],
['Hungary', 'HUN', 7],
['Ireland', 'IRE', 7],
['Iceland', 'ICE', 7],
['Japan', 'JAP', 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'.
```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'.

@ -502,10 +502,13 @@ console.log('Weight of an object in Newton: ', weightOfObject(100, 1.62)) // gra
### 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.
## 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: Level 1
@ -617,7 +620,7 @@ It ill be covered in other time
### 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
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.
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
@ -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
function letsLearnScope() {
console.log(a, b) // JavaScript 10, accessible
let c = 30
let value = false
if (true) {
// we can access from the function and outside the function but
// variables declared inside the if will not be accessed outside the if block
let a = 'Python'
let b = 20
let c = 30
let d = 40
value = !value
console.log(a, b, c) // Python 20 30
}
// 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()
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
//scope.js
@ -163,7 +165,7 @@ if (true){
for(let i = 0; i < 3; i++){
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
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
const users = {

@ -81,23 +81,22 @@ const higherOrder = n => {
}
return doWhatEver
}
return doSomething
}
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
const numbers = [1, 2, 3, 4]
const sumArray = arr => {
let sum = 0
const callBack = function(element) {
const callback = function(element) {
sum += element
}
numbers.forEach(callback)
arr.forEach(callback)
return sum
}
@ -115,7 +114,7 @@ const numbers = [1, 2, 3, 4]
const sumArray = arr => {
let sum = 0
numbers.forEach(function(element) {
arr.forEach(function(element) {
sum += element
})
return sum
@ -128,20 +127,20 @@ console.log(sumArray(numbers))
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
- 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.
```js
// syntax
function callBack() {
function callback() {
// code goes here
}
setInterval(callback, duration)
@ -151,10 +150,10 @@ setInterval(callback, duration)
function sayHello() {
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.
@ -195,9 +194,8 @@ arr.forEach((element, index, arr) => console.log(index, element, arr))
```js
let sum = 0;
const numbers = [1,2,3,4,5];
numbers.forEach(num => console.log(num)))
const numbers = [1, 2, 3, 4, 5];
numbers.forEach(num => console.log(num))
console.log(sum)
```
@ -211,8 +209,8 @@ console.log(sum)
```js
let sum = 0;
const numbers = [1,2,3,4,5];
numbers.forEach(num => sum += num))
const numbers = [1, 2, 3, 4, 5];
numbers.forEach(num => sum += num)
console.log(sum)
```
@ -349,6 +347,7 @@ console.log(countriesHaveFiveLetters)
```js
const scores = [
{ name: 'Asabeneh', score: 95 },
{ name: 'Lidiya', score: 98 },
{ name: 'Mathias', score: 80 },
{ name: 'Elias', score: 50 },
{ name: 'Martha', score: 85 },
@ -360,7 +359,7 @@ console.log(scoresGreaterEight)
```
```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
@ -391,7 +390,7 @@ _every_: Check if all the elements are similar in one aspect. It returns boolean
```js
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)
```
@ -402,11 +401,9 @@ true
```js
const bools = [true, true, true, true]
const areAllTrue = bools.every((b) => {
return b === true
})
const areAllTrue = bools.every((b) => b === true) // Are all true?
console.log(areAllTrue) //true
console.log(areAllTrue) // true
```
```sh
@ -448,9 +445,7 @@ const scores = [
{ name: 'John', score: 100 },
]
const score = scores.find((user) => {
return user.score > 80
})
const score = scores.find((user) => user.score > 80)
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 bools = [true, true, true, true]
const areSomeTrue = bools.some((b) => {
return b === true
})
const areSomeTrue = bools.some((b) => b === true)
console.log(areSomeTrue) //true
```
```js
const areAllStr = names.some((name) => typeof name === 'number')
const areAllStr = names.some((name) => typeof name === 'number') // Are all strings ?
console.log(areAllStr) // false
```
@ -556,7 +549,7 @@ users.sort((a, b) => {
return 0
})
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.

@ -245,7 +245,7 @@ Set(6) {1, 2, 3, 4, 5,6}
### 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
let a = [1, 2, 3, 4, 5]
@ -388,8 +388,8 @@ Norway Oslo
### Exercises:Level 1
```js
const a = {4, 5, 8, 9}
const b = {3, 4, 5, 7}
const a = [4, 5, 8, 9]
const b = [3, 4, 5, 7]
const countries = ['Finland', 'Sweden', 'Norway']
```
@ -432,9 +432,9 @@ const countries = ['Finland', 'Sweden', 'Norway']
// Your output should look like this
console.log(mostSpokenLanguages(countries, 3))
[
{'English':91},
{'French':45},
{'Arabic':25}
{English:91},
{French:45},
{Arabic:25}
]
```

@ -209,7 +209,7 @@ const rectangle = {
height: 10,
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)
```
@ -226,7 +226,7 @@ const rectangle = {
height: 10,
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
//Lets modify the object:width to 30 and perimeter to 80
@ -239,8 +239,8 @@ const rectangle = {
area: 200,
perimeter: 80
}
let { width, heigh, area, perimeter = 60 } = rectangle
console.log(width, height, area, perimeter) //20 10 200 80
let { width, height, area, perimeter = 60 } = rectangle
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.
@ -695,4 +695,4 @@ const users = [
```
🎉 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.
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
- localStorage

@ -33,7 +33,7 @@
## Promise
We human give or receive a promise to do some activity at some point in time. If we keep the promise we make others happy but if we do not keep the promise, it may lead discontentment. Promise in JavaScript has something in common with the above examples.
We human give or receive a promise to do some activity at some point in time. If we keep the promise we make others happy but if we do not keep the promise, it may lead discontentment. Promise in JavaScript has something in common with the above examples.
A Promise is a way to handle asynchronous operations in JavaScript. It allows handlers with an asynchronous action's eventual success value or failure reason. This lets asynchronous methods return values like synchronous methods: instead of immediately returning the final value, the asynchronous method returns a promise to supply the value at some point in the future.
@ -52,10 +52,10 @@ 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.
- 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.
```js
//Callback
const doSomething = callback => {
@ -73,7 +73,6 @@ const callback = (err, result) => {
}
doSomething(callback)
```
```sh
@ -81,7 +80,7 @@ doSomething(callback)
It did not go well
```
In this case the err is false and it will return the else block which is the result.
In this case the err is false and it will return the else block which is the result.
```js
const doSomething = callback => {
@ -106,7 +105,7 @@ doSomething((err, result) => {
### 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
// syntax
@ -134,21 +133,21 @@ doPromise
console.log(result)
})
.catch(error => console.log(error))
```
```
```sh
["HTML", "CSS", "JS"]
```
```sh
["HTML", "CSS", "JS"]
```
The above promise has been settled with resolve.
Let us another example when the promise is settled with reject.
The above promise has been settled with resolve.
Let us another example when the promise is settled with reject.
```js
// Promise
const doPromise = new Promise((resolve, reject) => {
setTimeout(() => {
const skills = ['HTML', 'CSS', 'JS']
if (skills.indexOf('Node') !== -1) {
if (skills.icludes('Node')) {
resolve('fullstack developer')
} else {
reject('Something wrong has happened')
@ -160,26 +159,26 @@ doPromise
.then(result => {
console.log(result)
})
.catch(error => console.log(error))
```
.catch(error => console.error(error))
```
```sh
Something wrong has happened
```
```sh
Something wrong has happened
```
## 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
const url = 'https://restcountries.com/v2/all' // countries api
fetch(url)
.then(response => response.json()) // accessing the API data as JSON
.then(data => { // getting the data
.then(data => {
// getting the 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
@ -198,9 +197,9 @@ square(2)
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
const square = async function (n) {
@ -218,7 +217,7 @@ Now, as you can see from the above example writing async in front of a function
Let us fetch API data using both promise method and async and await method.
- promise
```js
const url = 'https://restcountries.com/v2/all'
fetch(url)
@ -226,7 +225,7 @@ fetch(url)
.then(data => {
console.log(data)
})
.catch(error => console.log(error))
.catch(error => console.error(error))
```
- async and await
@ -238,7 +237,7 @@ const fetchData = async () => {
const countries = await response.json()
console.log(countries)
} catch (err) {
console.log(err)
console.error(err)
}
}
console.log('===== async and await')

@ -196,13 +196,13 @@ const names = ['Asabeneh', 'Mathias', 'Elias', 'Brook']
// iterating an array using regular for loop
let len = names.length;
for(let i = 0; i < len; i++){
console.log(names[i].toUpperCas())
console.log(names[i].toUpperCase())
}
// iterating an array using for of
for( const name of names) {
console.log(name.toUpperCase())
console.log(name.toUpperCasee())
}
// 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.
## 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)
[<< 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
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)
@ -148,7 +148,7 @@ asabeneh $ node -v
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
@ -156,7 +156,7 @@ There are many browsers out there. However, I strongly recommend 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)
@ -205,7 +205,7 @@ console.log('Hello, World!')
##### 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)
@ -239,7 +239,7 @@ This is a multiline comment
##### 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)
@ -255,7 +255,7 @@ So far, we saw how to display text using the _console.log()_. If we are printing
```js
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
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
console.log('Welcome to 30DaysOfJavaScript')
@ -405,8 +405,8 @@ External scripts in the _body_:
<title>30DaysOfJavaScript:External script</title>
</head>
<body>
//it could be in the header or in the body // Here is the recommended place
to put the external script
<!-- it could be in the header or in the body -->
<!-- Here is the recommended place to put the external script -->
<script src="introduction.js"></script>
</body>
</html>
@ -463,21 +463,22 @@ A collection of one or more characters between two single quotes, double quotes,
'Finland'
'JavaScript is a beautiful programming language'
'I love teaching'
'I hope you are enjoying the first day'`We can also create a string using a backtick`
;('A string could be just as small as one character as big as many pages')
'I hope you are enjoying the first day'
`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
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.
**Example:**
```js
true // if the light on ,the value is true
false // if the light off, the value is false
true // if the light is on, the value is true
false // if the light is off, the value is false
```
### Undefined
@ -486,7 +487,7 @@ In JavaScript, if we don't assign a value to a variable, the value is undefined.
```js
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
@ -531,6 +532,7 @@ Multiline commenting:
let age = 100;
let isMarried = true;
This is a Multiple line comment
*/
```

Loading…
Cancel
Save