-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexercise3.html
More file actions
35 lines (32 loc) · 1.01 KB
/
exercise3.html
File metadata and controls
35 lines (32 loc) · 1.01 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Exercise #3</title>
<script type="text/javascript">
function fun(x, y, z) { // synchronous/blocking function
if (Math.random()<0.5){
throw "Something is wrong!";
}
return x * y + z ** 3;
}
// let result = fun(1, 2, 3);
// console.log(`result is ${result}.`);
function gun(x, y, z) { // synchronous/blocking function
return new Promise((resolve, reject) => {
if (Math.random()<0.5){
reject("Something is wrong!");
}
setTimeout(() => {
resolve(x * y + z ** 3);
}, 5_000)
});
}
gun(1,2,3).then( result => console.log(`result is ${result}.`))
.catch( e => console.error(e) );
console.log("Application is running");
</script>
</head>
<body>
</body>
</html>