-
Notifications
You must be signed in to change notification settings - Fork 1
/
4await.js
42 lines (35 loc) · 799 Bytes
/
4await.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
let creditCheck = async function(amount, customer) {
if (!customer) {
throw new Error("missing customer!")
}
if (customer.credit > amount) {
return ("ok for:"+ amount.toFixed(2))
} else {
return ("need more credit")
}
}
main = async function(){
try{
let customer = {
name:"dave",
credit: 90,
}
console.log(await creditCheck(50,customer))
customer = {
name:"dave",
credit: 40,
}
console.log(await creditCheck(50,customer));
// Error conditions:
// Expected:
console.log(await creditCheck(50,null));
// Unexpected
console.log(await creditCheck(null,customer));
} catch (err) {
console.log("caught the error:")
console.log("---")
console.log(err.stack)
console.log("---")
}
}
main()