Try to understand the above comparisons with some logic. Remembering without any logic might be difficult.
JavaScript is somehow a wired kind of programming language. JavaScript code run and give you a result but unless you are good at it may not be the desired result.
JavaScript is somehow a wired kind of programming language. JavaScript code runs and gives you a result but unless you are good at it may not be the desired result.
As rule of thumb, if a value is not true with == it will not be equal with ===. Using === is safer than using ==. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types.
As a rule of thumb, if a value is not true with == it will not be equal with ===. Using === is safer than using ==. The following [link](https://dorey.github.io/JavaScript-Equality-Table/) has an exhaustive list of comparison of data types.
### Logical Operators
The following symbols are the common logical operators:
&&(ampersand) , ||(pipe) and !(negation).
The && operator gets true only if the two operands are true.
The || operator gets true either of the operand is true.
The || operator gets true if either of the operands is true.
The ! operator negates true to false and false to true.
```js
@ -254,7 +254,7 @@ let isMarried = !false // true
### Increment Operator
In JavaScript we use the increment operator to increase a value stored in a variable. The increment could be pre or postincrement. Let us see each of them:
In JavaScript we use the increment operator to increase a value stored in a variable. The increment could be pre or post-increment. Let us see each of them:
1. Pre-increment
@ -272,11 +272,11 @@ console.log(count++) // 0
console.log(count) // 1
```
We use most of the time post-increment. At least you should remember how to use post-increment operator.
We use most of the time post-increment. At least you should remember how to use the post-increment operator.
### Decrement Operator
In JavaScript we use the decrement operator to decrease a value stored in a variable. The decrement could be pre or postdecrement. Let us see each of them:
In JavaScript we use the decrement operator to decrease a value stored in a variable. The decrement could be pre or post-decrement. Let us see each of them:
1. Pre-decrement
@ -296,8 +296,8 @@ console.log(count) // -1
### Ternary Operators
Ternary operator allows to write a condition.
Another way to write conditionals is using ternary operators. Look at the following examples:
The ternary operator allows to write a condition.
Another way to write conditionals is by using ternary operators. Look at the following examples:
```js
let isRaining = true
@ -319,18 +319,18 @@ No need for a rain coat.
```js
let number = 5
number > 0
? console.log(`${number} is a positive number`)
: console.log(`${number} is a negative number`)
? console.log(`${number} is a positive number.`)
: console.log(`${number} is a negative number.`)
number = -5
number > 0
? console.log(`${number} is a positive number`)
: console.log(`${number} is a negative number`)
? console.log(`${number} is a positive number.`)
: console.log(`${number} is a negative number.`)
```
```sh
5 is a positive number
-5 is a negative number
5 is a positive number.
-5 is a negative number.
```
### Operator Precedence
@ -341,7 +341,7 @@ I would like to recommend you to read about operator precedence from this [link]
### Window alert() method
As you have seen at very beginning alert() method displays an alert box with a specified message and an OK button. It is a builtin method and it takes on argument.
As you have seen at the very beginning alert() method displays an alert box with a specified message and an OK button. It is a built-in method and it takes on argument.
```js
alert(message)
@ -381,14 +381,14 @@ These are not all the window methods we will have a separate section to go deep
## Date Object
Time is an important thing. We like to know the time a certain activity or event. In JavaScript current time and date is created using JavaScript Date Object. The object we create using Date object provides many methods to work with date and time.The methods we use to get date and time information from a date object values are started with a word _get_ because it provide the information.
Time is an important thing. We like to know the time a certain activity or event. In JavaScript current time and date is created using JavaScript Date Object. The object we create using Date object provides many methods to work with date and time.The methods we use to get date and time information from a date object values are started with a word _get_ because it provides the information.
1. Write three JavaScript statement which provide truthy value.
2. Write three JavaScript statement which provide falsy value.
1. Write three JavaScript statements which provide truthy value.
2. Write three JavaScript statements which provide falsy value.
5. Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log()
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 prompts the user to enter side a, side b, and side c of the triangle and calculate the perimeter of triangle (perimeter = a + b + c)
1. Get length and width using prompt and calculate an area of rectangle (area = length x width and the perimeter of rectangle (perimeter = 2 x (length + width))
1. Get radius using prompt and calculate the area of a circle (area = pi x r x r) and circumference of a circle(c = 2 x pi x r) where pi = 3.14.
1. Get length and width using prompt and calculate an area of rectangle (area = length x width) and the perimeter of rectangle (perimeter = 2 x (length + width))
1. Get the radius using prompt and calculate the area of a circle (area = pi x r x r) and the circumference of a circle(c = 2 x pi x r) where pi = 3.14.
1. Calculate the slope, x-intercept and y-intercept of y = 2x -2
1. Slope is m = (y<sub>2</sub>-y<sub>1</sub>)/(x<sub>2</sub>-x<sub>1</sub>). Find the slope between point (2, 2) and point(6,10)
1. Compare the slope of above two questions.
1. Compare the slope of the above two questions.
1. Calculate the value of y (y = x<sup>2</sup> + 6x + 9). Try to use different x values and figure out at what x value y is 0.
1. Writ a script that prompt a user to enter hours and rate per hour. Calculate pay of the person?
1. Write a script that prompts a user to enter hours and rate per hour. Calculate the pay of the person.
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 prompts the user to enter number of years. Calculate the number of seconds a person can live. Assume someone lives just hundred years
```sh
Enter number of years you live: 100
You lived 3153600000 seconds.
```
1. Create a humanreadable time format using the Date time object
1. Create a human-readable time format using the Date time object
1. YYYY-MM-DD HH:mm
2. DD-MM-YYYY HH:mm
3. DD/MM/YYYY HH:mm
### Exercises: Level 3
1. Create a humanreadable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 )
1. Create a human-readable time format using the Date time object. The hour and the minute should be all the time two digits(7 hours should be 07 and 5 minutes should be 05 )
1. YYY-MM-DD HH:mm eg. 20120-01-02 07:05
[<< Day 2](../02_Day_Data_types/02_day_data_types.md) | [Day 4 >>](../04_Day_Conditionals/04_day_conditionals.md)