6th Jul 2018, 10:29 PM
Sina
Sina - avatar
6 ответов
+ 3
https://www.sololearn.com/learn/JavaScript/1206/
6th Jul 2018, 11:36 PM
Agent
Agent - avatar
+ 2
Sina navigator.getBattery return YET a Promise... if(navigator.getBattery) navigator.getBattery().then((battery) =>{ console.log(battery.level) }).catch((error) =>{ alert(error) }) else alert('navigator has not .getBattery')
6th Jul 2018, 11:54 PM
KrOW
KrOW - avatar
+ 1
Hi Sina, Your HTML doesn't call your JavaScript function.
6th Jul 2018, 10:59 PM
Janning⭐
Janning⭐ - avatar
+ 1
Yes KrOw your code is true but I want to write it as a function
7th Jul 2018, 7:39 AM
Sina
Sina - avatar
+ 1
What do you mean Agent
7th Jul 2018, 7:40 AM
Sina
Sina - avatar
+ 1
Hi Sina, Maybe I lack imagination on this one, but I'm not sure why you would only want to check to presence of the battery API without actually doing anything with the information other than make an alert, so I was looking for clues in your HTML file, but found that you didn't call the function there, only at the end of the JavaScript file and I didn't see anything that indicated that you wanted this to happen when the window loaded (for example). While SoloLearn does automatically tie the JavaScript file to the HTML file for you and automatically runs whatever you put in it, it just doesn't make sense under normal circumstances. If I were you, I would mark Kr0W's answer as best because you can just wrap his answer in a function (like the one you wanted, "function a()") and because it deviates the least from whatever you were trying to do (not sure, can't guess). For something a bit more objective-oriented, please see: https://code.sololearn.com/WP4xPvHQCD9y/?ref=app I hope this helps! ☺
7th Jul 2018, 8:59 PM
Janning⭐
Janning⭐ - avatar