Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function division(num) {
- let divisor = 0;
- if (num % 10 === 0) {
- divisor = 10;
- } else if (num % 7 === 0) {
- divisor = 7;
- } else if (num % 6 === 0) {
- divisor = 6;
- } else if (num % 3 === 0) {
- divisor = 3;
- } else if (num % 2 === 0) {
- divisor = 2;
- } else {
- console.log('Not divisible');
- }
- if (divisor !== 0){
- console.log(`The number is divisible by ${divisor}`);
- }
- }
- Решение с тернарен оператор:
- function division(num) {
- let divisor =
- num % 10 === 0? 10:
- num % 7 === 0? 7:
- num % 6 === 0? 6:
- num % 3 === 0? 3:
- num % 2 === 0? 2 : 'Not divisible';
- console.log(divisor !== 'Not divisible'? `The number is divisible by ${divisor}`: divisor);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement