2. *Accessing characters in a string*: We can access each character in a string using its index. In programming, counting starts from 0. The first index of the string is zero, and the last index is the length of the string minus one.
2. *Accessing characters in a string*: We can access each character in a string using its index. In programming, counting starts from 0. The first index of the string is zero, and the last index is the length of the string minus one.


Let us access different characters in 'JavaScript' string.
Let us access different characters in 'JavaScript' string.
1. Write a script that prompt the user to enter side a, side b, and side c of the triangle and and calculate the perimeter of triangle (perimeter = a + b + c)
1. Write a script that prompt the user to enter side a, side b, and side c of the triangle and calculate the perimeter of triangle (perimeter = a + b + c)
You are 15. You will be allowed to drive after 3 years.
You are 15. You will be allowed to drive after 3 years.
```
```
1. Write a script that prompt the user to enter number of years. Calculate the number of seconds a person can live. Assume someone 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 someone lives just hundred years
@ -82,7 +82,7 @@ ReferenceError: fistName is not defined
at <anonymous>:4:20
at <anonymous>:4:20
In any case it will be executed
In any case it will be executed
```
```
The catch block take a parameter. It is common to pass e, err or error as a parameter to the catch block. This parameter is an object and it has name and message keys. Lets use the name and message.
The catch block takes a parameter. It is common to pass e, err or error as a parameter to the catch block. This parameter is an object and it has name and message keys. Let's use the name and message.
@ -75,7 +75,7 @@ Some use case of Web Storages are
For the examples mentioned above, it makes sense to use localStorage. You may be wondering, then, when we should use sessionStorage.
For the examples mentioned above, it makes sense to use localStorage. You may be wondering, then, when we should use sessionStorage.
In cases, we want to to get rid of the data as soon as the window is closed. Or, perhaps, if we do not want the application to interfere with the same application that’s open in another window. These scenarios are served best with sessionStorage.
In cases, we want to get rid of the data as soon as the window is closed. Or, perhaps, if we do not want the application to interfere with the same application that’s open in another window. These scenarios are served best with sessionStorage.
Now, let us see how make use of these Web Storage APIs.
Now, let us see how make use of these Web Storage APIs.
The `new Dat().toLocaleString()` can also be used to display current date time. The `toLocaleString()` methods takes different arguments. You may learn more about date and time from this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString).
The `new Date().toLocaleString()` can also be used to display current date time. The `toLocaleString()` methods takes different arguments. You may learn more about date and time from this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString).
#### Loops
#### Loops
We coverer many types of loops in this challenges. The regular for loop, while loop, do while loop, for of loop, forEach loop and for in loop.
We covered many types of loops in this challenge. The regular for loop, while loop, do while loop, for of loop, forEach loop and for in loop.
@ -154,7 +154,7 @@ const allTitles = document.querySelectorAll('.title') // the same goes for selec
### Adding attribute
### Adding attribute
An attribute is added in the opening tag of HTML which gives additional information about the element. Common HTML attributes: id, class, src, style, href,disabled, title, alt. Lets add id and class for the fourth title.
An attribute is added in the opening tag of HTML which gives additional information about the element. Common HTML attributes: id, class, src, style, href,disabled, title, alt. Let's add id and class for the fourth title.
```js
```js
const titles = document.querySelectorAll('h1')
const titles = document.querySelectorAll('h1')
@ -351,7 +351,7 @@ As you have notice, the properties of css when we use it in JavaScript is going
### Exercise: Level 1
### Exercise: Level 1
1. Create an index.html file and put four p elements as above: Get the first paragraph by using **_document.querySelector(tagname)_** and tag name
1. Create an index.html file and put four p elements as above: Get the first paragraph by using **_document.querySelector(tagname)_** and tag name
2. Get each of the the paragraph using **_document.querySelector('#id')_** and by their id
2. Get each of the paragraphs using **_document.querySelector('#id')_** and by their id
3. Get all the p as nodeList using **_document.querySelectorAll(tagname)_** and by their tag name
3. Get all the p as nodeList using **_document.querySelectorAll(tagname)_** and by their tag name
4. Loop through the nodeList and get the text content of each paragraph
4. Loop through the nodeList and get the text content of each paragraph
5. Set a text content to paragraph the fourth paragraph,**_Fourth Paragraph_**
5. Set a text content to paragraph the fourth paragraph,**_Fourth Paragraph_**