@ -177,7 +188,8 @@ console.log(Math.max(-5, 3, 20, 4,5, 10)) // 20, returns the maximum value
const randNum = Math.random() // creates random number between 0 to 0.999999
console.log(randNum)
// Let create random number between 0 to 10
// Let us create random number between 0 to 10
const num = Math.floor(Math.random () * 11) // creates random number between 0 and 10
console.log(num)
@ -278,7 +290,9 @@ let language = 'JavaScript'
let job = 'teacher'
let age = 250
let fullName = firstName + space + lastName
let personInfoOne = fullName + '. I am ' + age + '. I live in ' + country; // ES5
console.log(personInfoOne)
```
@ -339,10 +353,10 @@ To create a template string, we use two backticks. We can inject data as express
**Example: 1**
```js
console.log(`The sum of 2 and 3 is 5`)
console.log(`The sum of 2 and 3 is 5`) // statically writing the data
let a = 2
let b = 3
console.log(`The sum of ${a} and ${b} is ${a + b}`)
console.log(`The sum of ${a} and ${b} is ${a + b}`) // injecting the data dynamically
```
**Example:2**
@ -389,9 +403,9 @@ Everything in JavaScript is an object. A string is a primitive data type that me
```js
let js = 'JavaScript'
console.log(js.length) // 10
console.log(js.length) // 10
let firstName = 'Asabeneh'
console.log(firstName.length) // 8
console.log(firstName.length) // 8
```
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 one minus the length of the string.
@ -404,18 +418,18 @@ Let us access different characters in 'JavaScript' string.
let string = 'JavaScript'
let firstLetter = string[0]
console.log(firstLetter) // J
console.log(firstLetter) // J
let secondLetter = string[1] // a
let secondLetter = string[1] // a
let thirdLetter = string[2]
let lastLetter = string[9]
console.log(lastLetter) // t
console.log(lastLetter) // t
let lastIndex = string.length - 1
console.log(lastIndex) // 9
console.log(string[lastIndex]) // t
console.log(string[lastIndex]) // t
```
1. *toUpperCase()*: this method changes the string to uppercase letters.
[<< Day 2](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/02_Day/02_day_data_types.md) | [Day 4 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/04_Day/04_day_conditionals.md)
--
[<< Day 2](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/02_Day/02_day_data_types.md) | [Day 4 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/04_Day/04_day_conditionals.md)

@ -47,17 +46,17 @@
## Booleans
A boolean data type represents one of the two values:_true_ or _false_. Boolean value is either true or false. The use of these data types will be clear when you start the comparison operator. Any comparisons return a boolean value which is either true or false.
A boolean data type represents one of the two values:_true_ or _false_. Boolean value is either true or false. The use of these data types will be clear when you start the comparison operator. Any comparisons return a boolean value which is either true or false.
**Example: Boolean Values**
```js
let isLightOn = true;
let isRaining = false;
let isHungry = false;
let isMarried = true;
let truValue = 4 > 3 // true
let falseValue = 3 <4//false
let isLightOn = true
let isRaining = false
let isHungry = false
let isMarried = true
let truValue = 4 > 3 // true
let falseValue = 3 <4//false
```
We agreed that boolean values are either true or false.
@ -67,7 +66,7 @@ We agreed that boolean values are either true or false.
- All numbers(positive and negative) are truthy except zero
- All strings are truthy
- The boolean true
### Falsy values
- 0
@ -85,15 +84,15 @@ It is good to remember those truthy values and falsy values. In later section, w
If we declare a variable and if we do not assign a value, the value will be undefined. In addition to this, if a function is not returning the value will be undefined.
```js
let firstName;
console.log(firstName); //not defined, because it is not assigned to a value yet
let firstName
console.log(firstName) //not defined, because it is not assigned to a value yet
```
## Null
```js
let empty = null;
console.log(empty); // -> null , means no value
let empty = null
console.log(empty) // -> null , means no value
```
## Operators
@ -117,36 +116,38 @@ Arithmetic operators are mathematical operators.
@ -245,16 +244,16 @@ In JavaScrip we use the increment operator to increase a value stored in a varia
```js
let count = 0
console.log(++count) // 1
console.log(count) // 1
console.log(++count) // 1
console.log(count) // 1
```
1. Post-increment
```js
let count = 0
console.log(count++) // 0
console.log(count) // 1
console.log(count++) // 0
console.log(count) // 1
```
We use most of the time post-increment. At leas you should remember how to use post-increment operator.
@ -267,16 +266,16 @@ In JavaScrip we use the decrement operator to decrease a value stored in a varia
```js
let count = 0
console.log(--count) // -1
console.log(count) // -1
console.log(--count) // -1
console.log(count) // -1
```
2. Post-decrement
```js
let count = 0
console.log(count--) // 0
console.log(count) // -1
console.log(count--) // 0
console.log(count) // -1
```
#### Ternary Operators
@ -326,7 +325,7 @@ I would like to recommend you to read about operator precendence 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 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.
```js
alert(message)
@ -340,7 +339,7 @@ Do not use too much alert because it is destructing and annoying, use it just fo
### Window prompt() method
The window prompt methods display a prompt box with an input on your browser to take input values and the input data can be stored in a variable. The prompt() method takes two arguments. The second argument is optional.
The window prompt methods display a prompt box with an input on your browser to take input values and the input data can be stored in a variable. The prompt() method takes two arguments. The second argument is optional.
🌕 You have boundless energy. You have just completed day 3 challenge and you are three steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
🌕 You have boundless energy. You have just completed day 3 challenge and you are three steps a head in to your way to greatness. Now do some exercises for your brain and for your muscle.
1. Write a script that prompt the user to enter base and height of the triangle and calculate an area of a triangle (area = 0.5 x b x h).
1. Write a script that prompt the user to enter base and height of the triangle and calculate an area of a triangle (area = 0.5 x b x h).
```sh
Enter base: 20
Enter height: 10
The area of the triangle is 50
```
```sh
Enter base: 20
Enter height: 10
The area of the triangle is 50
```
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)
```sh
Enter side a: 5
Enter side b: 4
Enter side c: 3
The perimeter of the triangle is 12
```
2. 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))
3. 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.
4. Calculate the slope, x-intercept and y-intercept of y = 2x -2
5. Slope is (m = y2-y1/x2-x1). Find the slope between point (2, 2) and point(6,10)
6. Compare the slope of above two questions.
7. Calculate the value of y (y = x^2 + 6x + 9). Try to use different x values and figure out at what x value y is 0.
8. Writ a script that prompt a user to enters hours and rate per hour. Calculate pay of the person?
```sh
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
```
9. 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
You lived 3153600000 seconds.
```
```sh
Enter side a: 5
Enter side b: 4
Enter side c: 3
The perimeter of the triangle is 12
```
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. Calculate the slope, x-intercept and y-intercept of y = 2x -2
1. Slope is (m = y2-y1/x2-x1). Find the slope between point (2, 2) and point(6,10)
1. Compare the slope of above two questions.
1. Calculate the value of y (y = x^2 + 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 enters hours and rate per hour. Calculate pay of the person?
```sh
Enter hours: 40
Enter rate per hour: 28
Your weekly earning is 1120
```
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
You lived 3153600000 seconds.
```
## 3. Exercises: Booleans Part
@ -539,7 +538,7 @@ Boolean value is either true or false.
## 4. Exercises: Comparison Operators
Figure out the result of the following comparison expression first without using console.log(). After you decide the result confirm it using console.log()
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. 4 > 3
1. 4 >= 3
@ -552,7 +551,7 @@ Figure out the result of the following comparison expression first without using
1. 4 != '4'
1. 4 == '4'
1. 4 === '4'
Find the length of python and jargon and make a falsy comparison statement.
Find the length of python and jargon and make a falsy comparison statement.
## 5. Exercises: Logical Operators
@ -616,7 +615,7 @@ You are 25. You are old enough to drive
1. What is the minutes now?
1. Find out the numbers of seconds elapsed from January 1, 1970 to now.