-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.js
More file actions
130 lines (108 loc) · 2.54 KB
/
practice.js
File metadata and controls
130 lines (108 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//alert('welcome');
const teams=[
{
id:1,
clubName:'wolves',
totalPlayer:34
},
{
id:2,
clubName:'chelsea',
totalPlayer:25
},
{
id:3,
clubName:'barca',
totalPlayer:20
}
]
//const teamwolve=teams[0].totalPlayer
//console.log(teamwolve);
const teamJson=JSON.stringify(teams);
console.log(teamJson);
let i=0;
while(i<teams.length){
console.log(`${teams[i]}`);
i++
};
//for loops
for(let team of teams){
console.log(team.id)
};
//for each
teams.forEach(function(team){
console.log(team.clubName);
});
//map
const myteam=teams.map(team=>team.clubName)
console.log(myteam);
//filter
const noPlayers=teams.filter(team=>team.totalPlayer>20)
.map(team=>team.clubName)
console.log(noPlayers);
//conditional statement
const name=teams[1].clubName;
const checkLengthName=name.length>7?clubName.length:'false';
console.log(checkLengthName);
color='red';
switch(color){
case 'red':
console.log('this is red');
break;
case 'blue':
console.log('this is blue')
break;
default:{
console.log('non color')
}
};
//function
function multiply(num1=3,num2=1){
return num1*num2;
}
console.log(multiply());
//arrow function
const addNum=(num1, num2)=>num1+num2;
console.log(addNum(2,2));
//constructor function
/* function School(schoolName,founder,dob){
this.schoolName=schoolName;
this.founder=founder;
this.dob = new Date(dob);
}
//prototype
School.prototype.getBirthYear=function(){
return this.dob;
};
School.prototype.getFullName=function(){return `${this.schoolName} ${this.founder}`
};
School.prototype.class=8;
*/
//class
class School{
constructor(schoolName,founder,dob) {
this.schoolName=schoolName;
this.founder=founder;
this.dob = new Date(dob);
}
getBirthYear(){
return this.dob.getFullYear()
}
getFullName(){
return `${this.schoolName} ${this.founder}`
}
};
//instantiate object
const school1=new School('ggs','egbetokun',6-7-1998);
console.log(school1.schoolName);
console.log(school1.dob);
console.log(school1)
console.log(school1.getBirthYear());
console.log(school1.getFullName())
const inputEvent=document.querySelector('#name')
inputEvent.addEventListener('input' ,updateEvent)
function updateEvent(e){
e.preventDefault();
const p=document.querySelector('p');
p.textContent=inputEvent.value;
}