Advertisement
tr00per92

05-divisionBy3

Jul 15th, 2014
585
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function dividedByThree(num) {
  2.     var sumOfDigits = 0;
  3.     while (num > 0) {
  4.         sumOfDigits += num % 10;
  5.         num = Math.floor(num / 10);
  6.     }
  7.     if (sumOfDigits % 3 == 0) {
  8.         console.log("the number is divided by 3 without remainder");
  9.     } else {
  10.         console.log("the number is not divided by 3 without remainder");
  11.     }
  12. }
  13. dividedByThree(12);
  14. dividedByThree(189);
  15. dividedByThree(591);
  16. dividedByThree(13);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement