forked from Varanasi-Software-Junction/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpromise.html
More file actions
36 lines (30 loc) · 662 Bytes
/
promise.html
File metadata and controls
36 lines (30 loc) · 662 Bytes
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
<!DOCTYPE html>
<html>
<head>
<title>Promise</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script>
function f1(n)
{
var promise = new Promise(function(resolve, reject) {
if(n%2==0)
resolve('Your Promise Accepted');
else
reject('Your Promise Rejected');
})
promise
.then(function(successMsg) {
console.log(successMsg);
}, function(errorMsg) {
//To error handler function is invoked
console.log(errorMsg);
})
}
</script>
</head>
<body>
Output<div id="output"></div><br/>
<input type="button" value="Promise" onclick="f1(4)"><br/>
</body>
</html>