rendered paste body<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title> </title> <script type="text/javascript"> function timeToSeconds(inputTime) { var hour = 0; var minute = 0; var second = 0; var splits = inputTime.split(":"); if (splits.length == 3) { hour = splits[0]; minute = splits[1]; second = splits[2]; } if (splits.length == 2) { hour = 0; minute = splits[0]; second = splits[1]; } if (splits.length == 1) { hour = 0; minute = 0; second = splits[0]; } var totalSeconds = parseInt(hour * 60 * 60); totalSeconds += parseInt(minute * 60); totalSeconds += parseInt(second); return totalSeconds; } </script> </head> <body> <script> /* Test data: */ /* [ input , expected value] */ /* [ hh:mm:ss, seconds ] */ var times = [ ['10:12:30','36750'], ['2:2:30','7350'], ['01:12:33','4353'], ['12:33','753'], ['2:33','153'], ['3','3'], ['03','3'], ['02:33','153'], ['33','33'] ]; for (var i = 0; i < times.length; i++) { document.write((timeToSeconds(times[i][0]) == times[i][1]) + '<br/>'); } /* * Expected output is a list of the word 'true' **/ </script> </body></html>