Skip to content

Commit 3218ca5

Browse files
committed
Lecture 07
1 parent 2fc53d7 commit 3218ca5

File tree

7 files changed

+106
-0
lines changed

7 files changed

+106
-0
lines changed

Lecture07/array_ops/rms.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
let arr = [2, 3, 4]
2+
3+
let rmsValue = Math.sqrt(((arr.map(item => item*item))
4+
.reduce((acum, item) => {
5+
return acum+item
6+
})
7+
)/arr.length)
8+
9+
10+
console.log(rmsValue)

Lecture07/class.js

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Person{
2+
constructor(name, age){
3+
this.name = name;
4+
this.age = age;
5+
}
6+
7+
isAdult() {
8+
if(this.age < 18)
9+
{
10+
return false;
11+
}
12+
else return true
13+
}
14+
}
15+
16+
let p1 = new Person("Joe", 25);
17+
console.log(p1.isAdult());

Lecture07/ex1.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
let obj = {
2+
a: 10,
3+
b: 20,
4+
c: "Some Text"
5+
}
6+
7+
console.log(obj)
8+
9+
let obj2 = {
10+
a: "Some Text",
11+
fn: function() {
12+
return "fun"
13+
}
14+
}
15+
16+
console.log(obj2)
17+
console.log(obj2.fn)
18+
console.log(obj2.fn())

Lecture07/ex2.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let obj = {
2+
a: 20,
3+
b: 30,
4+
sum: function() {
5+
return this.a + this.b
6+
}
7+
}
8+
9+
function WhatIsThis() {
10+
console.log(this === global)
11+
}
12+
13+
console.log(WhatIsThis())

Lecture07/index.html

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
7+
<title>Document</title>
8+
<script src="prototypes.js"></script>
9+
</head>
10+
<body>
11+
12+
</body>
13+
</html>

Lecture07/new.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
function Person(Name, Age) {
2+
this.name = Name;
3+
// this.Age = Age;
4+
this.isAdult = function() {
5+
if(this.Age > 18) return true;
6+
else return false;
7+
}
8+
this.isAdult = function() {
9+
if(this.Age > 18) return true;
10+
else return false;
11+
}
12+
}
13+
14+
let p1 = new Person("Dhruv", 16)
15+
let p2 = new Person("Joe", 30);
16+
17+
let p3 = Person("John", 17)
18+
19+
console.log(p1.isAdult())
20+
console.log(p2.Age)
21+
console.log(p2.name)
22+
// console.log(p3)

Lecture07/prototypes.js

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
let food = {
2+
// veg: true,
3+
// taste: "delicious"
4+
}
5+
6+
let fruit = Object.create(food)
7+
fruit.taste = "sweet";
8+
9+
let Mango = Object.create(fruit)
10+
Mango.color = "Yellow"
11+
12+
13+
console.log(Mango)

0 commit comments

Comments
 (0)