Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a JavaScript function divisionBy3(number) that finds the sum of digits of integer number n
- (n > 9) and checks if the sum is divided by 3 without remainder. Write JS program divisionChecker.js
- to check a few numbers. The result should be printed on the console
- (“the number is divided by 3 without remainder” or “the number is not divided by 3 without remainder”). */
- "user strict";
- function divisionBy3(number) {
- if (number > 9) {
- var sum = 0;
- do {
- sum += number % 10;
- number = parseInt(number / 10);
- } while (number);
- if (!(sum % 3)) {
- console.log('the number is divided by 3 without remainder');
- } else {
- console.log('the number is not divided by 3 without remainder');
- }
- } else {
- console.error('Error! - The number must been bigger from 9!');
- }
- }
- divisionBy3(6);
- divisionBy3(12);
- divisionBy3(188);
- divisionBy3(591);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement