+ 8
Well, you may as well monitor the battery and see how it's going. Mine's just a quick-off; there are better implementations in CodePlayground I think.
https://code.sololearn.com/WM633Cfn7I69/?ref=app
+ 2
Try this
{
navigator.vibrate(9999999);
}
It drain battery at the rate of 1% per 2 minutes
+ 1
Just do a lot of useless stuff that targets as many different parts of the phone as possible.
Lots of useless multiplication and division to use up the CPU, lots of useless webgl on a canvas to use up the GPU, lots of loading of different images and websites from the internet to use up Wifi. Use the WebAudio API to play sounds. If you don't mind browser popups asking for permission use bluetooth and the camera and the microphone too.
0
"Educational purposes"
0
@Donald - From what I understand, JavaScript alone isn't something that will drain your battery. Rather, it's when JavaScript initiates the phone to poll a web server for some sort of update.
Therefore, you'd likely need to write some JavaScript with an AJAX callback with a high polling frequency of something like every 1 or 2 seconds. A more effective battery drainer could be done in a mobile app with the ability to run the high frequency polling in the background. Therefore, you could be draining the battery while working on another app.
0
Here's my unintentional coding mistake that drained my battery VERY fast:
function displayTime() {
myTime = new date();
document.getElementById("example").innerHTML = myTime;
setInterval(displayTime, 1000); //THIS is the part I messed up (setInterval mutiplies).
}
This code (my dumbest mistake) COMPLETELY drained my battery!