Create PT Question with Time Calucations

I have a student that is interested in creating a Pace calculator similar the one on http://www.coolrunning.com/engine/4/4_1/96.shtml

The calculator would have the ability to answer in seconds, however, I am not sure how or if this can be done or if there are resources for the student to use. Has anyone had a student interested in a project like this and if so any suggestions. They only want to do it if they can have it work with seconds. Plus, I am not sure how much I can help them with something like this. Any suggestions would be helpful. Thanks.

Time is a notoriously hard thing to compute with. Yes, before you do arithmetic you need to get everything into seconds. But if you ask for minutes and seconds as distinct inputs you should be able to do that arithemetic.

Should be:

  • ask for hours, mins, secs
  • convert to secs (hours * 60 * 60 + mins * 60 + secs)
  • calculate pace in secs (e.g. totalSecs / numMiles)
  • convert back to separate hours, mins, secs. <-- this is where the arithmetic has to be thoughtful.

One thing to take advantage of is a function called parseInt(...) for which there is no block, but you can type it.

parseInt will return the whole number portion of a decimal value. SO parseInt(32.1) evaluates to 32. parseInt(32.9999) also evaluates to 32.

This is convenient if you’re trying to do something like arithmetic to convert seconds back into minutes + seconds. For example. If you have 347 seconds, you could divide 347/60 to get the number of minutes. 347/60 evaluates to 5.78333… 5 mins + some number of seconds. but parseInt(347/60) evaluates to 5. 5*60 is 300 seconds. So then 347-300 is 47. So you can work out that 347 seconds is 5 mins 47 seconds.

var totalSecs = //...some large number of seconds
var mins = parseInt(totalSecs/60);
var secs = totalSecs - (mins*60);
console.log("pace = "+mins+"m "+secs+"s");

I think it’s within bounds to tell the student about the parseInt function and how it can be used to help this arithmetic.
I also thinks it’s in bounds to tell the student how to do the arithmetic because the task isn’t evaluating your arithmetic skills – the fuzzy part is if the student is going to claim that this is their algorithm. But if they don’t hear it from you googling “converting seconds to minutes in javascript” should get you something like what I’ve shared above and it’s certainly legal for a student to look up how to solve a problem using online resources.