-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
441 lines (405 loc) · 9.42 KB
/
script.js
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
//variable introduction and concatination
/*
var firstName='divakar';
var lastName='verma';
console.log(firstName);
console.log(lastName);
console.log('your first name is:'+firstName+ ' and last name is:' +lastName);
*/
//variable manuplition
/*
var firstName,lastName,age;
firstName='divakar';
lastName='verma';
age=21;
console.log(firstName+lastName+age);
age='twenty one ';
console.log(firstName+lastName+age);
*/
//mathmatical operator
/*
var year=2019;
age=21;
var yearJohn=year-age;
console.log(yearJohn);
var num1,num2;
num1=12;
num2=32;
console.log(num1+num2);
//logical operator
var name='john';
var age=21;
var ageJohn=age>32;
console.log(ageJohn);
// typeof operator
// user input
var firstName=prompt('enter your first name');
var lastName=prompt('enter your last name');
alert('Hellow'+firstName+lastName);
*/
// coding chalange 1
/*
var johnMass=56;
var johnHeight=1.5;
var markMass=67;
var markHeight=2;
var john_BMI,mark_BMI;
john_BMI=johnMass/(johnHeight*johnHeight);
mark_BMI=markMass/(markHeight*markHeight);
var johnBMI=john_BMI>mark_BMI;
console.log('john BMI is greater then mark '+johnBMI);
*/
//if else statement
/*
var name='john';
var age=2;
if(age>19){
console.log(name+" is young");
}
else{
console.log(name+'not young');
}
//second mathod
var johnAge=age<16;
if(johnAge){
console.log(name+'not young');
}
else{
console.log(name+' young')
}
*/
//nested if else
/*
var name='john';
var age=22;
if(age<13){
console.log(name+' is chiled');
}
else if(age>=13 && age<21){
console.log(name+' is teenion');
}
else if(age>=21 && age<30){
console.log(name+' is young');
}
else{
console.log(name+' is man')
}
*/
// typeof operator
/*
var nam='divakar';
console.log(typeof nam);
var a= 12;
console.log(typeof a);
//ternary operator
var name='john';
var age=2;
age>=21? console.log(name+' is young'):console.log(name+' is not young');
*/
//var age=2;
//var drink=age>=21? 'bear':'jusce';
//console.log(drink);
//switch statement
/*
var name='divakar';
var job='doctor';
switch(job){
case'teacher':
console.log(name+' teaches kids code');
break;
case'engineer':
console.log(name+' design software');
break;
case'doctor':
console.log(name+' see patent');
break;
default:
console.log(name+' do somthing');
break;
}
var age =21;
switch(true){
case age<13:
console.log(name+' is a child');
break;
case age>=13 && age<21:
console.log(name+' is teenager');
break;
case age>=21 && age<40:
console.log(name+' is young boy');
break;
default:
console.log(name+' is man');
break;
}
*/
//falsy undefined, '',NaN etc
/*
var height=0;
if(height){
console.log('defined');
}
else{
console.log('undefined');
}
var age =21;
if(age=='21'){
console.log('your age is '+age);
}
else{
console.log('tour age is not '+age);
}
var age =21;
if(age==='21'){
console.log('your age is '+age);
}
else{
console.log('tour age is not '+age);
}
*/
//**************
// coding chalange 2
/*
var johnScore1,johnScore2,johnScore3;
johnScore1=89;
johnScore2=130;
johnScore3=103;
var johnAvg=(johnScore1+johnScore2+johnScore3)/3;
var mikeScore1,mikeScore2,mikeScore3;
mikeScore1=116;
mikeScore2=99;
mikeScore3=123;
var mikeAvg=(mikeScore1+mikeScore2+mikeScore3)/3;
switch(true){
case johnAvg>mikeAvg:
console.log("john win the game and it's score is "+johnAvg);
break;
case mikeAvg>johnAvg:
console.log("mike win the game and it's score is "+mikeAvg);
break;
default:
console.log('draw the match');
}
var johnScore=(97+87+130)/3;
var mikeScore=(216+99+123)/3;
var marryScore=(197+134+185)/3;
console.log(johnScore,mikeScore,marryScore);
switch(true){
case johnScore>mikeScore && johnScore>marryScore:
console.log('john win the match and its score '+johnScore+'points');
break;
case mikeScore>johnScore && mikeScore>marryScore:
console.log('mike win the match and its score '+mikeScore+'points');
break;
case marryScore>johnScore&&
marryScore>mikeScore:
console.log('marry win the match and its score '+marryScore+'points');
break;
default:
console.log('draw the match');
}
*/
//*************
//function
/*
function ageCalculate(year){
return 2019-year;
}
console.log(ageCalculate(1998));
console.log(ageCalculate(1988));
console.log(ageCalculate(1978));
console.log(ageCalculate(1968));
// function inside function
function isretired(year,name){
var age=ageCalculate(year);
var retiredment=65-age;
if(retiredment>0){
console.log(name+' is retired after '+retiredment);
}
else{
console.log(name+' already retired');
}
}
isretired(1998,'divakar');
isretired(1989,'john');
isretired(1967,'make');
isretired(1950,'janae');
//**********
//function expresion
var whatYouDo=function(job,name){
switch(job){
case 'teacher':
return name+' teaches kids code';
case 'engineer':
return name+' design software';
case 'doctor':
return name+' see patent';
case'desinor':
return name+' design best website';
default:
return name+' does something else';
}
}
console.log(whatYouDo('teacher','divakar'));
console.log(whatYouDo('doctor','john'));
console.log(whatYouDo('engineer','divakar'));
console.log(whatYouDo('developer','divakar'));
console.log(whatYouDo('desinor','divakar'));
*/
//******************
// arrey
/*
var name=['divakar','dhurv','prerna'];
var year=new Array(1998,1999,2000,'divakar');
console.log(name);
console.log(year);
// array operation
year.push('divya','verma');
year.unshift('Mr.')
console.log(year);
//pop operation
year.pop();
console.log(year);
year.shift();
console.log(year);
//indexOf
console.log(year.indexOf('divya'));
var name=new Array('divakar',1998,'verma','divya');
var test=name.indexOf('prerna')>=0? 'present':'not present';
console.log(test);
*/
//***********
//coding chalange 3
/*
function calculateBill(bill){
switch(true){
case bill<50:
return b1=.2*bill;
case bill>=50&&bill<200:
return b2=.15*bill;
case bill>=200:
return b3=.1*bill;
default:
return 'none';
}
}
function totalAmount(bill){
var payBill=calculateBill(bill);
var pay=[payBill];
console.log('John give the tips '+pay);
}
totalAmount(67);
totalAmount(45);
totalAmount(256);
*/
//******
/*
function calculateTip(bill){
var percantage;
switch(true){
case bill<50:
percantage=.2;
break;
case bill>=50&&bill<200:
percantage=.15;
break;
case bill>=200:
percantage=.1;
break;
default:
percantage=-1;
}
return percantage*100;
}
var bills=[67,456,45];
var tip=[calculateTip(bills[0]),calculateTip(bills[1]),calculateTip(bills[2])];
console.log('Tip '+tip);
var finalAmount=[bills[0]+tip[0],bills[1]+tip[1],bills[2]+tip[2]];
console.log('final Amount '+finalAmount);
*/
/***********/
// object
/*
var john={
firstName:'john',
lastName:'smith',
birthYear:1998,
age:21,
family:['mike','marry','jany'],
music:['s1','s2','s3'],
};
console.log(john);
console.log(john.firstName);
console.log(john['firstName']);
//***********
var john=new Object()
john.firstname='john';
john.lastname='smith';
john.age=21;
console.log(john);
//********
var john={
firstName:'john',
lastName:'smith',
birthYear:1998,
family:['mike','marry','jany'],
music:['s1','s2','s3'],
calculateAge:function(birthYear){
return 2019-birthYear;
}
};
console.log(john.calculateAge(1998));
var john={
firstName:'john',
lastName:'smith',
birthYear:1998,
family:['mike','marry','jany'],
music:['s1','s2','s3'],
calculateAge:function(){
return 2019-this.birthYear;
}
};
console.log(john.calculateAge());
var john={
firstName:'john',
lastName:'smith',
birthYear:1998,
family:['mike','marry','jany'],
music:['s1','s2','s3'],
calculateAge:function(){
this.age=2019-this.birthYear;
}
};
john.calculateAge();
console.log(john);
********** coading chalange 4*/
var john={
firstName:'john',
mass:67,
height:1.7,
caljohnBMI:function(){
this.johnBMI=this.mass/(this.height*this.height);
}
};
var mark={
frrstName:'mark',
mass:185,
height:2.6,
calmarkBMI:function(){
this.markBMI=this.mass/(this.height*this.height)
}
};
john.caljohnBMI();
mark.calmarkBMI();
console.log(john);
console.log(mark);
switch(true){
case john['johnBMI']>mark['markBMI']:
console.log('John BMI is greater than mark and its value is '+john.johnBMI);
break;
case john['johnBMI']<mark['markBMI']:
console.log('Mark BMI is greater than John and its value is '+mark.markBMI);
break;
default:
console.log('Both BMI is equal '+john['johnBMI']);
}