Javascript battery percentage

HTML
<p></p>
CSS
html, body { height: 100%; } body { display: flex; flex-wrap: nowrap; align-items: center; justify-content: center; } p { background-color: black; font-size: 1.25rem; color: white; padding: 1rem; border-radius: .5rem; }
JAVASCRIPT
const p = document.querySelector('p'); navigator.getBattery().then((b) => { const l = b.level; const s = l * 100 + '%'; p.innerHTML = `BATTERY: ${s}`; });
Expand for more options Login