-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample-promise.js
74 lines (63 loc) · 1.7 KB
/
example-promise.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
68
69
70
71
72
73
/*function getTempCallback (location, callback){
callback(undefined,78);
callback('City not found');
}
getTempCallback('Pamplona', function(err, temp){
if(err){
console.log('error', err);
}else{
console.log('success', temp);
}
});
function getTempPromise(location){
return new Promise(function(resolve, reject){
setTimeout(function(){
resolve(79);
reject('City not found');
}, 1000);
});
};
getTempPromise('Pamplona').then(function(temp){
console.log('promise success', temp);
}, function(error){
console.log('promise error', err);
});*/
//Challenge Area
/*function addPromise(a, b){
return new Promise(function (resolve, reject){
if (typeof a === 'number' && typeof b === 'number'){
resolve(a+b);
}else{
reject('A & B need to be numbers!');
}
});
}
addPromise(10,40).then(function(sum){
console.log('success', sum);
}, function(err){
console.log('error', err);
});
addPromise('andres',9).then(function(sum){
console.log('this should not show up', sum);
}, function(err){
console.log('this should appear', err);
})*/
/*function addPromiseString(a,b){
return new Promise(function(resolve, reject){
if(typeof a === 'string' && typeof b === 'string'){
resolve(a+b);
}else{
reject('Have to be strings!')
}
});
}
addPromiseString('hola',' tio').then(function(value){
console.log('Success: ',value);
}, function(err){
console.log('Error: ', err);
});
addPromiseString(4,'hola').then(function(value){
console.log('This should not appear', value);
}, function(err){
console.log('Error: ', err);
});*/