Advertisement
YavorJS

Sum Seconds

May 9th, 2016
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. function solve(arr) {
  2. var x = Number(arr[0]);
  3. var y = Number(arr[1]);
  4. var z = Number(arr[2]);
  5. var totalSeconds = x + y + z;
  6. // console.log(totalSeconds);
  7. var hours = Math.floor(totalSeconds / 60);
  8. // console.log(hours);
  9. var seconds = totalSeconds - hours * 60;
  10. // console.log(seconds);
  11.  
  12. var result = "";
  13. if (seconds < 10) {
  14. seconds = "0" + seconds;
  15. }
  16.  
  17. if (totalSeconds >= 0 && totalSeconds <= 59) {
  18. result = "0:" + seconds;
  19. console.log(result);
  20. }
  21. else if (totalSeconds >= 60 && totalSeconds <= 119) {
  22. result = "1:" + seconds;
  23. console.log(result);
  24. }
  25. else if (totalSeconds >= 120 && totalSeconds <= 179) {
  26. result = "2:" + seconds;
  27. console.log(result);
  28. }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement