• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Can anyone help me in JavaScript ?

chocobaR

Golden Member
I have to write a program that when a user puts let's say 12537 seconds, it has to tell him what it is in hours, minutes and seconds.

12537 seconds --> 3 hours 28 minutes 57 seconds

Thanks.
 
I just don't know how to do it. I have problems in programming classes, I'm way better with Photoshop, Illustrator and Flash. I need help starting it and finding the logic of how to build it.
 
The first thing you have to understand is how you got *your* answer in the first place... This script works by calling it with an input value of the seconds you want to break down... Ex. gettime(12537);


<script>
function gettime(temp){
secs = temp%60;
mins = ((temp-secs)/60)%60;
hours = (((temp-secs)/60)-mins)/60;

document.write("Hours: " + hours + ", Minutes: " + mins + ", Seconds: " + secs);
}
</script>


I think the code is pretty much self-explanatory... 😉 May not be the most elegant, and I'm pretty sure there are other ways of doing this... but at 4 in the morning I'm not going to try to hard... 🙂
 
Note, the above script will NOT be a good example for any input > 86400... 😉 as that will go beyond the 24 hour limit... 😉
 
Back
Top