Ad
Fundamentals
Strings
Data Types

Better than a loop! Still using padStart one the minutes.

Code
Diff
  • function minutes(minutes){
      var hours = Math.floor(minutes/60);
      minutes = minutes - hours*60;
        return hours.toString() + ":" + minutes.toString().padStart(2, 0);
    }
    • function minutes(minutes){
    • var hours = 0;
    • while (minutes >= 60){
    • minutes -= 60;
    • hours += 1;
    • };
    • var hours = Math.floor(minutes/60);
    • minutes = minutes - hours*60;
    • return hours.toString() + ":" + minutes.toString().padStart(2, 0);
    • }
Fundamentals
Strings
Data Types

Using a loop!

Code
Diff
  • function minutes(minutes){
      var hours = 0;
      while (minutes >= 60){
        minutes -= 60;
        hours += 1;
        };
        return hours.toString() + ":" + minutes.toString().padStart(2, 0);
    }
    • function minutes(num){
    • return num % 60 < 10 ? Math.floor(num/60) + ':' + '0' + (num % 60) : Math.floor(num/60) + ':' + (num % 60)
    • function minutes(minutes){
    • var hours = 0;
    • while (minutes >= 60){
    • minutes -= 60;
    • hours += 1;
    • };
    • return hours.toString() + ":" + minutes.toString().padStart(2, 0);
    • }