Hi fellow students, I am trying to solve a question I found on a book which is from a range o numbers, print those divisible by 3, them print those only divisible by 5, them print those divisible by both 3 and 5. I have the following code by its not completely right…
let numbers = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20];
for(let i = 0; i < numbers.length; i++){
if(numbers[i] % 3 === 0){
console.log(numbers[i] + ' is div by 3');
} else if(numbers[i] % 5 === 0){
console.log(numbers[i] + ' is div by 3')
} else if(numbers[i] % 3 === 0 && numbers[i] % 5 === 0){
console.log(numbers[i] + ' are both div by 3 and 5' );
} else {
console.log("no fizz or buzz");
}
}