I am creating a JS function that takes a time input in minutes only and divides that number by an inputted digit. I would like to know how we use Javascript to convert that result into minutes and seconds.

For instance, 30 (1800 seconds) divided by 4 = 450 seconds. How do I show that as 7:30? I can divide by 60 to get 7.5, but I don't know how to go from there. I got as far as the following, then got stuck.

You can use Math.floor to remove the decimal amount, leaving you with the number of minutes.To get the number of seconds, you can use the modulus operator with what you divided by, to obtain the remainder.

I went to w3schools.com for Javascript variables and each line of their list of variables end in a semi-colon, and there are no single-quotes around their digits. They are using double-quotes around strings.

In terms of syntax, it doesn't matter whether single or double-quotes are used. However, since HTML commonly uses double-quotes for its attributes, it has become a standard practice to use single-quotes for javascript strings.

Whichever way you decide to use, just be consistent with it. If possible, pick a set of [code conventions and stick with them. There are many [url="http://www.martinrinehart.com/articles/javascript-conventions.html"]different code conventions](http://javascript.crockford.com/code.html), but many of them tend to converge to the same fundamental ideas.

StevenHu
—
2011-05-19T22:59:41Z —
#19

Thanks! Regarding Post #12, I removed the vars that followed commas. But it still doesn't work.

Paul_Wilkins
—
2011-05-19T23:02:51Z —
#20

StevenHu said:

Thanks! Regarding Post #12, I removed the vars that followed commas. But it still doesn't work.

Submit your code in this javascript lint page, and it will show you the most obvious problem that need to be fixed in your code.

If you want your code to be fully without problems, there's a much harsher jslint process, but it's well worth it, especially with "the good parts" enabled.