I borrowed a script to help me convert a series of digits. However, I’m told that 2 seconds is being displayed as “:2” instead of “:02.” I thought I fixed the problem with a series of conditionals, but that doesn’t seem to have addressed the issue. Can you show me where I went wrong?
...
var minutes = Math.floor(runtime / 60), // get the minute figure as a digit for the time readout
seconds = runtime % 60; /* use modulus operator to get the remainder and convert into seconds figure for the time readout */
seconds = parseInt(seconds, 10);
if (seconds === 0) {
seconds = "00";
}
if (seconds === 1) {
seconds = "01";
}
if (seconds === 2) {
seconds = "02";
}
if (seconds === 3) {
seconds = "03";
}
if (seconds === 4) {
seconds = "04";
}
if (seconds === 5) {
seconds = "05";
}
if (seconds === 6) {
seconds = "06";
}
if (seconds === 7) {
seconds = "07";
}
if (seconds === 8) {
seconds = "08";
}
if (seconds === 9) {
seconds = "09";
}
var runtime2 = minutes + ":" + seconds; // concatenate everything into minutes and seconds