My substr method not working in js

What is the difference between the uncommented lines vs the commented(which is grabbing mm and multiplying by 60 then concatenating with ss)?

function getSeconds(str) {
  // var mm = str.substr(0,2);
  // var ss = str.substr(3,5);
  // return mm*60+ss;
  var nums = str.split(':'),
    mm = +nums[0],
    ss = +nums[1];
  return mm * 60 + ss;
}

getSeconds("13:25");

88 thoughts on “My substr method not working in js”

Leave a Comment