I am an amateur programmer writing simple HTML/Javascript programs, and I recently ran into something I can't explain. I have a small program that sets the starting and ending time for an appointment. The format is HHMMSS for both. I hard-coded the start times I needed, for example 103000 or 123000, and then wrote a line of code to add 10000 to get the end time. This worked fine until I tried 073000 + 10000. The result, instead of being 083000 (or at least 83000), ended up being 40208.
I would write the problem off as an issue with the leading 0, but 093000 + 10000 = 103000, which is what I would expect. What is going on with 073000 + 10000 = 40208?
I fixed the program a different way, but I am stumped by this. Many thanks for any explanation you can provide.
Here is some simple code from w3schools that produces 40208 as the addition result:
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var x = 073000 + 10000;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>