6th Jul 2018, 7:56 PM
Sina
Sina - avatar
15 odpowiedzi
+ 2
hi Sina first you need to fix typo , promise ==> should be Promise then you need to use resolve and reject Regards
6th Jul 2018, 9:17 PM
Mohammed Naji (Joker)
Mohammed Naji (Joker) - avatar
+ 2
navigator.getBattery().then(function(battery) { document.write(battery.level * 100); } ) see this is a promise too but it dowsn't has result or resolve
6th Jul 2018, 10:06 PM
Sina
Sina - avatar
+ 2
Warn here you are USING the promise and in this case it accept only the resolved callback (the function passed to .then) https://developer.mozilla.org/en-US/docs/Web/API/Navigator/getBattery
6th Jul 2018, 10:13 PM
KrOW
KrOW - avatar
+ 1
That its empty :)
6th Jul 2018, 8:03 PM
KrOW
KrOW - avatar
+ 1
We need your code to take a look and help you🙄
6th Jul 2018, 8:06 PM
Sad
Sad - avatar
+ 1
☺☺☺excuse me I forgot
6th Jul 2018, 8:44 PM
Sina
Sina - avatar
+ 1
You have forget to use resolve (and if needed reject) and use right syntax for Promise (not promise): function f0(a){ return new Promise((resolve , reject)=>{ var x = 0; if(x % 2 == 0){ x = a*5 } else{ x = a*10 } resolve(x) }) } f0(5).then((result)=>{ console.log(result) }) https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
6th Jul 2018, 9:21 PM
KrOW
KrOW - avatar
+ 1
Sina Have you added resolve(x) at end like in my sample code?
6th Jul 2018, 9:30 PM
KrOW
KrOW - avatar
+ 1
Sina dont worry.. He has contacted me for notify something... Dont take cure, we have removed comments
6th Jul 2018, 9:47 PM
KrOW
KrOW - avatar
+ 1
if I want to write it with resolve and result how it is going to be?
6th Jul 2018, 10:17 PM
Sina
Sina - avatar
0
why it doesn't console?
6th Jul 2018, 9:28 PM
Sina
Sina - avatar
0
yes you say true
6th Jul 2018, 9:35 PM
Sina
Sina - avatar
0
Also we can write this code in another code. so why do we must learn promis in js?
6th Jul 2018, 9:35 PM
Sina
Sina - avatar
0
what?
6th Jul 2018, 9:46 PM
Sina
Sina - avatar