We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cf23af0 commit 989e050Copy full SHA for 989e050
JavaScript/5-promise.js
@@ -0,0 +1,25 @@
1
+'use strict';
2
+
3
+const sum = (a, b) => new Promise((resolve, reject) => {
4
+ if (typeof(a) === 'number' && typeof(b) === 'number') {
5
+ resolve(a + b);
6
+ } else {
7
+ reject(new Error('a and b should be numbers'));
8
+ }
9
+});
10
11
+sum(2, 3)
12
+ .then(data => {
13
+ console.log(data);
14
+ })
15
+ .catch(err => {
16
+ console.log(err.message);
17
+ });
18
19
+sum(7, 'A')
20
21
22
23
24
25
0 commit comments