-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJavascrpits tutorial
511 lines (376 loc) · 10.1 KB
/
Javascrpits tutorial
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
// var Name= "Dayo owns";
// var Car= "BMW";
// var food="and he also likes to eat rice"
// console.log(Name, Car, food);
// let animal="Ram"
// animal="Dog"
// //const pi= 3.142
// var Name= "Dayo";
// var food= "rice";
// var movies="Batman"
// console.log(' My name is ' + Name + ' and I like to eat ' + food + ' and to watch ' + movies);
// var number1= 12
// var number2= 3
// console .log(number1 / number2);
// var age= 12
// console.log(typeof(age))
// // Data types
// //String
// //number
// //BigInteger
// //Boolean
// //undefined
// //null
// //object
// //symbol
// //string
// var school= 'Appclick'
// //Biginteger
// var km = 12222222222
// var is_online= true
// //number
// var age = 22
// console.log(typeof(age));
// var laptop
// console.log(typeof (laptop));
// //null
// var electronics= null
// console.log(typeof (electronics))
// //array
// //var listofballers = ["Dele Alli", 5, true ()]
// //objects
// var user= {
// name:'Dayo',
// gender:'Male'
// }
// var brand= Symbol()
// console.log (typeof (brand));
// var todaysDate = new Date()
// console.log(todaysDate. getDate());
// //comparison operators
// //== (Checks for value)
// //!= (inverse of ==)
// //=== (checks for both value and data type)
// //>
// //<
// //<=
// //>
// var num1= 5
// var num2= 5
// console.log(num1 === num2);
// var score= 200
// var age= 16
// console.log (score >= 200 && age >=14)
// var age= 18
// var drivers_licence= true
// console.log (drivers_licence>=true && age >=18)
// //Indexof
// var school= 'appclickade'
// console.log(school.lastIndexOf('p'));
// //match method
// console.log (school.match('ade'));
// console.log(school.matchAll('ade'));
// console.log(school.includes('ade'));
// // alert ('Hello word!!')
// // prompt ('kindly input your name')
// //Number methods
// var age= 16.5
// var newAge= age. toString()
// console.log(typeof(newAge));
// console.log (age. toExponential());
// console.log (age. toFixed());
// console.log (age. valueOf());
// console.log (age. toPrecision(5));
// console.log (Math.PI);
// let speed= 240.9
// console.log(Math.floor(speed));
// console.log (Math.floor(Math.random() * 100));
// var pi= Math.PI
// var radius= 2
// console.log(pi * radius**2);
// //arrays
// var countries= ['Poland', 'Fiji', 'Canada' ]
// console.log(countries.length);
// console.log(countries[0]);
// var Bagpack =[]
// //append to the end of an array
// Bagpack.push('water bottle', 'spoon')
// console.log(Bagpack);
// //adds an items to the begining of an array
// Bagpack.unshift('Book')
// console.log(Bagpack);
// //remove from the end
// Bagpack.pop()
// console.log(Bagpack);
// Bagpack.shift()
// console.log(Bagpack);
// const s= 'tech, computer, science';
// console.log(s.split(', '));
// console.log(Array.isArray(s));
// console.log(s.indexOf('tech'));
// // const y= 12;
// // if(y>11) {
// // console.log ('y is more than 11');
// // }
// // const x= 12;
// // if(x>11) {
// // console.log ('x is more than 11');
// // }
// const x= 10;
// const color= x > 11 ? 'red' : 'blue';
// //function
// function addNum(num1=1, num2=1) {
// console.log (num1 + num2)
// }
// addNum();
// //constructor function
// class person {
// constructor(firstName, lastName, dob) {
// this.firstName = firstName;
// this.lastName = lastName;
// this.dob = new Date (dob);
// }
// getBirthYear() {
// return this.dob.getFullYear();
// }
// getFullName() {
// return `${this.firstName} ${this.lastName}`;
// }
// }
// //instatiate objects
// const person1= new person ('Dayo', 'Ola', '4-12-2000');
// console.log(person1. getFullName());
// // var passkey= prompt ('kindly input password !')
// // var OriginalPassword= 'appclick'
// // if(passkey== OriginalPassword){
// // alert('password is correct')
// // }
// // else{
// // alert('password is incorrect');
// // }
// //an admission validation
// // var Jambscore = prompt ('enter your jambscore')
// // var age= prompt ('kindly input your age')
// // if(Jambscore>=200 && age>=16){
// // alert('You are eligible')
// // }
// // else if (age>=16 || Jambscore>=180){
// // alert('you are not eligible but you can visit a private school')
// // }
// // else{
// // alert('you are not eligible')
// // }
// // var password= prompt('enter your password')
// // if (password.length <=8){
// // alert('password should not be less than 8 xxx')
// // }
// // else if(!password.includes('@')){
// // alert('password must have @ sign')
// // }
// // else{
// // alert('password is correct!')
// // }
// // var number= prompt('enter your number')
// // if (number>0){
// // alert('number is positive')
// // }
// // else if (number<0){
// // alert('number is negative')
// // }
// // else if (number == 0){
// // alert('number is zero')
// // }
// // else {
// // alert('This is not a number')
// // }
// //Switch Operator
// var DayOfWeek = new Date
// switch (DayOfWeek.getDay()) {
// case 3:
// console.log('today is wednesday stay sharp');
// break;
// case 5:
// console.log('today is friday stay strong');
// break;
// case 1:
// console.log('today is Monday stay wicked');
// break;
// case 0:
// console.log('today is Sunday stay wicked');
// break;
// }
// // var number = prompt('enter your number')
// // console.log(Math.random(Math.floor)*10);
// // var RandomNumber= Math.round(Math.random() * 10);
// // var UserInput= prompt ('kindly enter a number from 0-10');
// // if(RandomNumber==UserInput){
// // // alert(` computer picked ${RandomNumber} Congratulations number matched `)
// // alert ("computer picked" + RandomNumber + "Congratulations number matched")
// // }
// // else{
// // alert(` Computer picked ${RandomNumber} Try again You lost `)
// // }
// //Loops
// //For loop (Loops through a block of code in number of times)
// //While loop (Infinix loop)
// //Do-while loop
// // for (let number = 0; number <= 10; number+2) {
// // console.log(number);
// // }
// for(let num= 1700; num <=3600; num++){
// if (num % 5==0 && num % 7==0) {
// console.log(num);
// }
// }
// //FUNCTION (block of code that runs anytime you call it)
// //name function
// function printText() {
// console.log('hello world');
// }
// //anon function
// let bella = function(){
// console.log('hello from dayo');
// }
// //arroww function
// const Ajoke = () => {
// console.log('hello world from dayo');
// }
// bella()
// bella()
// bella()
// printText()
// Ajoke()
// const greet =(name)=>{
// console.log(' good morning ' + name);
// }
// greet ('stanley')
// greet ('musa')
// function square( number) {
// return(
// `the square of ${number} is: ${number**2}`
// )
// }
// console.log(square(38));
// function convert( dollar) {
// return(
// dollar * 1500
// )
// }
// console.log(convert(10));
// function convert( degree) {
// return(
// (degree * 9/5) +32
// )
// }
// console.log(convert(1));
// function agecalculator(year){
// var currentYear = new Date().getFullYear()
// return(
// currentYear - year
// )
// }
// console.log(agecalculator(2000));
// function capitalize(string) {
// return(
// string.toUpperCase()
// )
// }
// console.log(capitalize('girl'));
// //MAP AND FILTER METHODS IN ARRAYS
// var numbers = [1,2,3,4,5,6,7,,8,9,10]
// for(num1 in numbers){
// console.log(num1 * 2);
// }
// var emails = ['ayo@gmail.com', 'dayo@mail.com']
// for(mail in emails){
// console.log(`${emails[mail]} hello how are you`);
// }
// //map all even numbers
// var newnumbers = [2,3,4,5,6]
// var newnum = newnumbers.map((ade) => {
// return (
// ade * 2
// )
// })
// console.log(newnum);
// //filter
// var filterevennumber = newnumbers.filter((num) => {
// return(
// num % 2 == 0
// )
// })
// console.log(filterevennumber);
// //search filter
// const foodItems = ['amala', 'rice', 'eba', 'egg', 'eggsauce', 'egg plant']
// const search = 'egg';
// const filteredString = foodItems.filter(food => food.includes(search))
// console.log(filteredString);
// //DOM MANIPULATION
// var joke = document.querySelector(' .dayoo')
// console.log(joke);
// // var BTN = document.querySelector('.btn')
// // BTN.addEventListener('click', function () {
// // alert ('button clicked!!!')
// // })
// var dark = document.querySelector('.dark')
// var container= document.querySelector('.container')
// dark.addEventListener('click', function(){
// container.classList.toggle('dark-mode')
// })
// //functions and methods
// //declaration and definition
// //arguements & parameters
// //call back and higher order function
// //functions and methods
// function sum(a, b){
// return a + b;
// }
// //default parameter (works when the user is not inputing correct function)
// function calc (a, b=0){
// return (2 * (a + b));
// }
// calc(2, 3)
// //reset parameters (allows a function to accept any number of arguements)
// function collectThings(x, ...y){
// console.log(x);
// console.log(y);
// }
// collectThings(1,2,3,4,5,6,7,8,9);
// //arrow function
// const add = (x, y) =>x + y
// //nested function (deiinfes function inside functiom)
// function outer(){
// console.log('outer');
// function inner(){
// console.log('inner');
// }
// }
// outer();
// //closure (nested function is a closure, the inner function can be accessed from variables from outer closure)
// function outer(x){
// function inner (y){
// return x + y;
// }
// return inner;
// }
// const outerReturn = outer(10);
// outerReturn
// //callback function
// function foo(bar){
// if(itsNights){
// bar();
// }
// if(isDrinkersOverCheckOnlune){
// bar();
// }
// }
// //high order function (takes one or more function as arguements and may retuen a function)
// //reverse a number
// function reverse_a_number(n)
// {
// n = n + "";
// return n.split("").reverse().join("");
// }
// console.log(Number(reverse_a_number(32243)));
// outerReturn(2)
//array