-1

I am getting a NaN result. Clearly something is not right. But I cannot figure is out what is wrong in the calculations. Heres the code:

var totalTime = video.duration;
var milliToHours = function (value) {
  return value / 60 / 60;
}
milliToHours (totalTime);
// howerver it returns NaN in console
Alan Larimer
  • 589
  • 8
  • 24
Libby Lebyane
  • 167
  • 2
  • 14

1 Answers1

0

video.duration must be undefined at function execution. Add a console.log(value); statement to your function.

var totalTime;
var milliToHours = function(value) {
  console.log(value);
  return value / 60 / 60;
}
console.log(milliToHours(totalTime)); // undefined => NaN
totalTime = null;
console.log(milliToHours(totalTime)); // null => 0
totalTime = 39856.6757;
console.log(milliToHours(totalTime)); // 39856.6757 => 11.071298805555555
Alan Larimer
  • 589
  • 8
  • 24
  • yes it is video.duration its undefined but when I use the floating point value like you did in the last line it works fine – Libby Lebyane Oct 08 '17 at 16:34
  • When does `viideo.duration` have a value? Is there an event (i.e. video loaded) that is fired so that you know when you can use your `milliToHours` function? Without more details or code, there's not much more assistance that can be provided. – Alan Larimer Oct 08 '17 at 16:40