-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathasynchronus.js
67 lines (62 loc) · 1.4 KB
/
asynchronus.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
/*function doSomething(callback) {
callback();
}
function sayHi() {
console.log("Hi!");
}
doSomething(sayHi); //passing another function in a function as a refrence using callback called out other function
*/
//callback example 02
function hey(ret){
ret="yes"
console.log("return works! through callback "+ret);
}
function there(a,b,callback){
let ret;
addup=a+b;
console.log("main function calling : "+addup);
callback(ret);
}
there(3,4,hey); // passing another function in a function as a refrence using callback called out other function
/*
function judge(grade) {
switch (true) {
case grade == "A":
console.log("You got an", grade, ": amazing!");
break;
case grade == "B":
console.log("You got a", grade, ": well done!");
break;
case grade == "C":
console.log("You got a", grade, ": alright.");
break;
case grade == "D":
console.log("You got a", grade, ": hmmm...");
break;
default:
console.log("An", grade, "! What?!");
}
}
function getGrade(score, callback) {
let grade;
switch (true) {
case score >= 90:
grade = "A";
break;
case score >= 80:
console.log(score);
grade = "B";
break;
case score >= 70:
grade = "C";
break;
case score >= 60:
grade = "D";
break;
default:
grade = "F";
}
callback(grade);
}
getGrade(85, judge);
*/