-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.html
More file actions
582 lines (478 loc) · 12.5 KB
/
Copy pathfunction.html
File metadata and controls
582 lines (478 loc) · 12.5 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
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
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<button onclick="tellFortune()">Try it</button>
<button onclick="calculateDogAge()">calculate Dog Age</button>
<button onclick="calculateSupply()">calculate Supply</button>
<button onclick="greet()">hello</button>
<button onclick="cube()">cube</button>
<button onclick="multiply()">multiply</button>
<button onclick="largerNubmer()">larger Nubmer</button>
<button onclick="smallerNubmer()">smallerNubmer</button>
<script>
/*
1
Write a function named tellFortune that:
takes 4 arguments: number of children,
partner's name, geographic location, job title.
outputs your fortune to the screen like so:
"You will be a X in Y, and married to Z with N kids."
Ex: tellFortune('software engineer', 'Jordan', 'Alice', 3);
=> "You will be a software engineer in Jordan, and married to Alice with 3 kids."
*/
function tellFortune() {
let job = prompt("Please enter your job title", "job title");
let location = prompt("Please enter your geographic location", "geographic location");
let partner= prompt("Please enter your partner's name", "your partner's name");
let children = prompt("Please enter your number of children", "the number of children");
console.log(`You will be a ${job} in ${location}, and married to ${partner} with ${children} kids`)
}
/*
2
Write a function named calculateDogAge that:
takes 1 argument: your puppy's age.
calculates your dog's age based on the conversion
rate of 1 human year to 7 dog years.
outputs the result to the screen like so:
"Your doggie is NN years old in dog years!"
Ex: calculateDogAge(1);
=> "Your doggie is 7 years old in dog years!"
*/
function calculateDogAge() {
let age = prompt("Please enter your puppy's age", "puppy's age");
console.log(`Your doggie is ${age*7} years old in dog years!`)
}
/*
3
Write a function named calculateSupply that:
takes 2 arguments: age, amount per day.
calculates the amount consumed for rest of the life (based on a constant max age 100).
outputs the result to the screen like so:
"You will need NN to last you until the ripe old age of X"
Ex: calculateSupply(30, 3);
=> 'You will need 76650 cups of tea to last you until the ripe old age of 100;
*/
function calculateSupply() {
let x = prompt("Please enter your age", "your age");
let y = prompt("Please enter your amount per day", "your amount per day");
console.log(`You will need ${(100-x)*365*y} cups of tea to last you until the ripe old age of 100`);
}
// /*
// 4
// Write a function called greet that:
// takes 1 argument: name.
// and it will return hello + name
// Ex: greet("Adam")
// => "Hello Adam"
// */
function greet() {
let n = prompt("Please enter your name", "your name");
console.log(`Hello ${n}`);
}
// /*
// 5
// what is the error:
// function double(cat) {
// return 2 * x;
// }
// function double(7) {
// return 2 * 7;
// }
// function double('7') {
// return 2 * 'x';
// }
//
// */
// /*
// 6
// fix these functions:
// func double1(x {
// return 2 * x ;
// }
// functiondouble2 x)
// return 2 * x;
// }
// function (x) double3 {
// return 2 * x;
// */
// /*
// 7
// Write a function called cube that:
// accept 1 parameter and calculate the cube of this number
// Ex: cube(4)
// => 64
// */
function cube(){
let y = prompt("Please enter a number", "number");
console.log(y**3)
}
// /*
// 8
// Write a function called multiply that:
// accept 2 parameters and calculate the multiply of these 2 numbers
// Ex: multiply(3,4)
// => 12
// Ex: multiply(5,4)
// => 20
// */
// function multiply(a,x){
// let a1 = prompt("Please enter your 1st number ", "the number ");
// let x1 = prompt("Please enter your 2nd number ", "the number ");
// console.log(a1 *x1)
// }
// /*
// 9
// Write a function called canIGetADrivingLicense that:
// accept 1 parameter represent the age
// and if the age greater than or equal to 20 return "yes you can"
// otherwise return "please come back after X years to get one"
// Ex: canIGetADrivingLicense(21)
// => "yes you can"
// Ex: canIGetADrivingLicense(17)
// => "please come back after 3 years to get one"
// Ex: canIGetADrivingLicense(20)
// => "yes you can"
// */
// function canIGetADrivingLicense(){
// let age1 = prompt("Please enter your age", "the age");
// if(age1>=20 ){
// console.log("yes you can")
// }else{
// console.log(`please come back after ${20-age1} years to get one`)
// }
// }
// /*
// 10
// Write a function called sameLength
// that accepts two strings as arguments,
// and returns true if those strings have the same length, and false otherwise.
// **hint: how we can know string length Ex: : "tree".length => 4
// Ex: sameLength("tree","clue")
// => true
// Ex: sameLength("tree","car")
// => false
// */
// function sameLength(){
// let a2 = prompt("Please enter your 1st word ", "the word ");
// let x2 = prompt("Please enter your 2nd word ", "the word ");
// if((a2.length)==(x2.length)){
// return true;
// }else{
// return false;
// }
// }
// /*
// 11
// Write a function called largerNubmer
// that accept two numbers as arguments,
// and return the first larger numbers
// Ex: largerNubmer(5,6)
// => 6
// Ex: largerNubmer(5,3)
// => 5
// */
// function largerNubmer(){
// let a3 = prompt("Please enter your 1st # ", "the number ");
// let x3 = prompt("Please enter your 2nd # ", "the number ");
// if(a3>x3){
// console.log(a3)
// }else{
// console.log(x3)
// }
// }
// /*
// 12
// Write a function called smallerNubmer
// that accept three numbers as arguments,
// and return the first smaller number
// Ex: smallerNubmer(8,6,7)
// => 6
// Ex: smallerNubmer(5,99,34)
// => 5
// Ex: smallerNubmer(5,99,3)
// => 3
// Ex: smallerNubmer(5,3,3)
// => 3
// */
// function smallerNubmer(){
// let a4 = prompt("Please enter your 1st Nubmer ", "the Nubmer ");
// let x4 = prompt("Please enter your 2nd Nubmer ", "the Nubmer ");
// let y4 = prompt("Please enter your 3rd Nubmer ", "the Nubmer ");
// if(a4<x4 && a4<y4){
// console.log(a)
// }else if (x4<a4 && x4<y4){
// console.log(x4)
// }else{
// console.log(y4)
// }
// }
// /*
// 13
// Write a function called shorterString
// that accept five string as an arguments,
// and return the first shorter string
// Ex: shorterString("air","school","car","by","github")
// => by
// Ex: shorterString("air","tr","car","by","github")
// => tr
// Ex: shorterString("by","tr","car","air","github")
// => by
// Ex: shorterString("air","by","car","school","github")
// => by
// Ex: shorterString("air","tr","by","car","github")
// => by
// Ex: shorterString("air","tr","car","github","by")
// => by
// */
// function shorterString(){
// let d1 = prompt("Please enter your 1st word ", "the word ");
// let d2 = prompt("Please enter your 2nd word ", "the word ");
// let d3 = prompt("Please enter your 1st word ", "the word ");
// let d4 = prompt("Please enter your 2nd word ", "the word ");
// let d5 = prompt("Please enter your 1st word ", "the word ");
// if((d1.length)<(d2.length)&&(d1.length)<(d3.length)&&(d1.length)<(d4.length)&&(d1.length)<(d5.length)){
// console.log(d1)
// }else if((d1.length)>(d2.length)&&(d2.length)<(d3.length)&&(d2.length)<(d4.length)&&(d2.length)<(d5.length)){
// console.log(d2)
// }else if((d3.length)<(d2.length)&&(d1.length)>(d3.length)&&(d3.length)<(d4.length)&&(d3.length)<(d5.length)){
// console.log(d3)
// }else if((d4.length)<(d2.length)&&(d1.length)>(d4.length)&&(d3.length)>(d4.length)&&(d4.length)<(d5.length)){
// console.log(d4)
// } else {
// console.log(d5)
// }}
// /*
// 14
// Write a function called longerString
// that accept four string as an arguments,
// and return the first longer string
// Ex: longerString("air","school","car","github")
// => school
// Ex: longerString("air","schoo","car","github")
// => github
// try all the cases (change the order of the longestString)
// */
// /*
// 15
// Write a function called isEven
// that accept 1 argument as a number,
// and return true if this number is even
// and false if this number is odd
// Ex: isEven(1)
// => false
// Ex: isEven(2)
// => true
// */
// function isEven(){
// if (x%2==0){
// console.log("true")
// }else{
// console.log("false")
// }
// }
// /*
// 16
// Write a function called isOdd
// that accept 1 argument as a number,
// and return true if this number is Odd
// and false if this number is Even
// Ex: isOdd(4)
// => false
// Ex: isOdd(5)
// => true
// */
// function isOdd(){
// if (x%2==1){
// console.log("true")
// }else{
// console.log("false")
// }
// }
// /*
// 17
// Write a function called positive
// that accept 1 argument as a number,
// and return the positive version of the number passed
// Ex: positive(4)
// => 4
// Ex: positive(-5)
// => 5
// */
// function positive(){
// let s =prompt("Please enter your Nubmer ", "the Nubmer ");
// if (s<0){
// s*=-1
// }
// console.log(s)
// }
// /*
// 18
// Write a function called fullName
// that accept two parameters, firstName and lastName,
// and returns the firstName and lastName concatenated
// together with a space in between.
// Ex: fullName("Adam","McCallen")
// => "Adam McCallen"
// Ex: fullName("Alex", "Mercer")
// => "Alex Mercer"
// */
// function fullName(){
// let firstName = prompt("Please enter your firstName ", "the firstName ");
// let lastName = prompt("Please enter your lastName word ", "the lastName ");
// console.log(`${firstName} ${lastName}`)
// }
// /*
// 19
// Write a function called average
// that takes five numbers as inputs
// and returns the average of those numbers.
// Ex: average(1,2,3,4,5)
// => 3
// Ex: average(5,7,9,3,5)
// => 5.8
// */
function average(){
let b,sum;
for(i=0;i<5;i++){
b = prompt("Please enter your no ", "the # ");
sum+=b
}
return sum/5;
}
// /*
// 20
// Write a function called randomNumber
// that didnt takes any parameter
// and returns a random number between 0-1
// ** hint: you can seacrh using MDN
// Ex: randomNumber()
// => 0.2278
// Ex: randomNumber()
// => 0.475
// */
// function randomNumber() {
// console.log(Math.random());
// }
// /*
// 21
// Write a function called randomBetweenNumbers
// that takes 2 parameters
// and returns a random number between them
// ** hint: you can seacrh using MDN
// Ex: randomBetweenNumbers(1,8)
// => 7.5412
// Ex: randomBetweenNumbers(3,100)
// => 23
// */
function randomBetweenNumbers(min,max) {
let m= Math.floor(Math.random()*(max-min)+min)
return m;
}
console.log(randomBetweenNumbers(-5,3));
// /*
// 22
// Write a function called scoreInUniversty
// that takes 1 parameters
// and returns the alpabet in the unevirsty
// A => 95-100
// B => 85-94
// C => 70-84
// D=> 50-69
// F=> 0-49
// Ex: scoreInUniversty(96)
// => "A"
// Ex: scoreInUniversty(3)
// => "F"
// Ex: scoreInUniversty(71)
// => "C"
// */
// function scoreInUniversty(score){
// let score;
// if (score<=100 && score>=0){
// if (score>94){
// return "A";
// }else if (score>84){
// return "B";
// }else if (score>70){
// return "C";
// }else if (score>50){
// return "D";
// }else {
// return "F";
// }
// }
// }
function scoreInUniversty(score){
score;
if(score<=100 && score>=0){
switch(true) {
case score>95:
return "A";
case score>84:
return "B";
case score>70:
return "C";
case score>50:
return "D";
default:
return "F";
break;
}}}
console.log(scoreInUniversty(99))
// return "A"; it will end the cond so we don't need to add break
//
//
// /*
// 23
// Write a function called counter
// that will returns a number bigger
// than the one that returnd before
// and start from 0
// Ex: counter()
// => 1
// Ex: counter()
// => 2
// Ex: counter()
// => 3
// */
let c=0
function counter(c){
return c++;
}
// /*
// 24
// Write a function called resetCounter
// that will reset the previuos function
// and return the number before reset and
// a string say that the counter reset
// Ex: counter()
// => 1
// Ex: counter()
// => 2
// Ex: counter()
// => 3
// Ex: resetCounter()
// => 3 and the counter reset now
// Ex: counter()
// => 1
// Ex: counter()
// => 2
// Ex: resetCounter()
// => 2 and the counter reset now
// Ex: counter()
// => 1
// */
function resetcounter(c){
return `${c}and the counter reset now`,c=0;
}
console.log(counter());
console.log(counter());
console.log(resetcounter());
</script>
</body>
</html>