You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: 03_Day_Booleans_operators_date/03_booleans_operators_date.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -31,7 +31,7 @@
31
31
- [Increment Operator](#increment-operator)
32
32
- [Decrement Operator](#decrement-operator)
33
33
- [Ternary Operators](#ternary-operators)
34
-
- [Operator Precendence](#operator-precendence)
34
+
- [Operator Precedence](#operator-precedence)
35
35
- [Window Methods](#window-methods)
36
36
- [Window alert() method](#window-alert-method)
37
37
- [Window prompt() method](#window-prompt-method)
@@ -333,9 +333,9 @@ number > 0
333
333
-5 is a negative number
334
334
```
335
335
336
-
### Operator Precendence
336
+
### Operator Precedence
337
337
338
-
I would like to recommend you to read about operator precendence from this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
338
+
I would like to recommend you to read about operator precedence from this [link](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence)
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))
569
569
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.
570
570
1. Calculate the slope, x-intercept and y-intercept of y = 2x -2
571
-
1. Slope is (m = y2-y1/x2-x1). Find the slope between point (2, 2) and point(6,10)
571
+
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)
572
572
1. Compare the slope of above two questions.
573
-
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.
573
+
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.
574
574
1. Writ a script that prompt a user to enter hours and rate per hour. Calculate pay of the person?
Copy file name to clipboardexpand all lines: 04_Day_Conditionals/04_day_conditionals.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -280,7 +280,7 @@ isRaining
280
280
281
281
### Exercises: Level 1
282
282
283
-
1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he neds to turn 18.
283
+
1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:'You are old enough to drive' but if not 18 give another feedback stating to wait for the number of years he needs to turn 18.
// console.log(arguments), arguments object not found in arrow function
272
-
// instead we use an a parameter followed by spread operator
272
+
// instead we use a parameter followed by spread operator (...)
273
273
console.log(args)
274
274
}
275
275
@@ -523,7 +523,7 @@ It Will be covered in other section.
523
523
9. Density of a substance is calculated as follows:_density= mass/volume_. Write a function which calculates _density_.
524
524
10. Speed is calculated by dividing the total distance covered by a moving object divided by the total amount of time taken. Write a function which calculates a speed of a moving object, _speed_.
525
525
11. Weight of a substance is calculated as follows: _weight = mass x gravity_. Write a function which calculates _weight_.
526
-
12. Temperature in oC can be converted to oF using this formula: _oF = (oC x 9/5) + 32_. Write a function which convert oC to oF _convertCelciusToFahrenheit_.
526
+
12. Temperature in oC can be converted to oF using this formula: _oF = (oC x 9/5) + 32_. Write a function which convert oC to oF _convertCelsiusToFahrenheit_.
527
527
13. Body mass index(BMI) is calculated as follows: _bmi = weight in Kg / (height x height) in m2_. Write a function which calculates _bmi_. BMI is used to broadly define different weight groups in adults 20 years old or older.Check if a person is _underweight, normal, overweight_ or _obese_ based the information given below.
- [Setting new key for an object](#setting-new-key-for-an-object)
31
+
- [Object Methods](#object-methods)
32
+
- [Getting object keys using Object.keys()](#getting-object-keys-using-objectkeys)
33
+
- [Getting object values using Object.values()](#getting-object-values-using-objectvalues)
34
+
- [Getting object keys and values using Object.entries()](#getting-object-keys-and-values-using-objectentries)
35
+
- [Checking properties using hasOwnProperty()](#checking-properties-using-hasownproperty)
36
+
- [💻 Exercises](#-exercises)
37
+
- [Exercises: Level 1](#exercises-level-1)
38
+
- [Exercises: Level 2](#exercises-level-2)
39
+
- [Exercises: Level 3](#exercises-level-3)
40
40
41
41
# 📔 Day 8
42
42
43
43
## Scope
44
44
45
-
Variable is the fundamental part in programming. We declare variable to store different data types. To declare a variable we use the key word _var_, _let_ and _const_. A variable can declared at different scope. In this section we will see the scope, scope of variables when we use var or let.
45
+
Variable is the fundamental part in programming. We declare variable to store different data types. To declare a variable we use the key word _var_, _let_ and _const_. A variable can be declared at different scope. In this section, we will see the scope variables, scope of variables when we use var or let.
46
46
Variables scopes can be:
47
47
48
-
- Window
49
48
- Global
50
49
- Local
51
50
52
-
Variable can be declared globally or locally or window scope. We will see both global and local scope.
53
-
Anything declared without let, var or const is scoped at window level.
51
+
Variable can be declared globally or locally scope. We will see both global and local scope.
52
+
Anything declared without let, var or const is scoped at global level.
54
53
55
54
Let us imagine that we have a scope.js file.
56
55
57
-
### Window Scope
56
+
### Window Global Object
58
57
59
58
Without using console.log() open your browser and check, you will see the value of a and b if you write a or b on the browser. That means a and b are already available in the window.
60
59
61
60
```js
62
61
//scope.js
63
-
a ='JavaScript'//is a window scope this found anywhere
64
-
b =10// this is a window scope variable
62
+
a ='JavaScript'//declaring a variable without let or const make it available in window object and this found anywhere
63
+
b =10// this is a global scope variable and found in the window object
65
64
functionletsLearnScope() {
66
65
console.log(a, b)
67
66
if (true) {
@@ -96,13 +95,18 @@ console.log(a, b) // JavaScript 10, accessible
96
95
97
96
A variable declared as local can be accessed only in certain block code.
98
97
98
+
- Block Scope
99
+
- Function Scope
100
+
99
101
```js
100
102
//scope.js
101
103
let a ='JavaScript'// is a global scope it will be found anywhere in this file
102
104
let b =10// is a global scope it will be found anywhere in this file
105
+
// Function scope
103
106
functionletsLearnScope() {
104
107
console.log(a, b) // JavaScript 10, accessible
105
108
let value =false
109
+
// block scope
106
110
if (true) {
107
111
// we can access from the function and outside the function but
108
112
// variables declared inside the if will not be accessed outside the if block
@@ -111,7 +115,7 @@ function letsLearnScope() {
111
115
let c =30
112
116
let d =40
113
117
value =!value
114
-
console.log(a, b, c) // Python 20 30
118
+
console.log(a, b, c, value) // Python 20 30 true
115
119
}
116
120
// we can not access c because c's scope is only the if block
117
121
console.log(a, b, value) // JavaScript 10 true
@@ -138,9 +142,9 @@ if (true){
138
142
console.log(gravity) // 9.81
139
143
140
144
for(var i =0; i <3; i++){
141
-
console.log(i) //1, 2, 3
145
+
console.log(i) //0, 1, 2
142
146
}
143
-
console.log(i)
147
+
console.log(i)// 3
144
148
145
149
```
146
150
@@ -163,13 +167,13 @@ if (true){
163
167
// console.log(gravity), Uncaught ReferenceError: gravity is not defined
164
168
165
169
for(let i =0; i <3; i++){
166
-
console.log(i) //1, 2, 3
170
+
console.log(i) //0, 1, 2
167
171
}
168
172
// console.log(i), Uncaught ReferenceError: i is not defined
169
173
170
174
```
171
175
172
-
The scope *let* and *const*is the same. The difference is only reassigning. We can not change or reassign the value of const variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will writ clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for array, object, arrow function and function expression.
176
+
The scope *let* and *const*are the same. The difference is only reassigning. We can not change or reassign the value of the `const` variable. I would strongly suggest you to use *let* and *const*, by using *let* and *const* you will write clean code and avoid hard to debug mistakes. As a rule of thumb, you can use *let* for any value which change, *const* for any constant value, and for an array, object, arrow function and function expression.
173
177
174
178
## 📔 Object
175
179
@@ -252,14 +256,14 @@ const person = {
252
256
console.log(person.firstName)
253
257
console.log(person.lastName)
254
258
console.log(person.age)
255
-
console.log(person.location)
259
+
console.log(person.location)// undefined
256
260
257
261
// value can be accessed using square bracket and key name
258
262
console.log(person['firstName'])
259
263
console.log(person['lastName'])
260
264
console.log(person['age'])
261
265
console.log(person['age'])
262
-
console.log(person['location'])
266
+
console.log(person['location'])// undefined
263
267
264
268
// for instance to access the phone number we only use the square bracket method
0 commit comments