This is my first question so sorry if it's dumb. I'm trying to do the classic FizzBuzz exercise in the console using javascrypt, putting the changes into an array for 1 to 100. So far:
let nums = [];
for (let i = 1; i <= 100; i++) {
nums.push(i);
}
for (num of nums) {
if (nums[num] % 5 === 0) {
nums[num] = "Buzz";
console.log("Buzz");
}
else if (nums[num] % 3 === 0) {
nums[num] = "Fizz";
console.log("Fizz");
}
else if (nums[num] % 3 === 0 && nums[num] % 5 === 0) {
nums[num] = "FizzBuzz";
console.log("FizzBuzz");
}
else {
console.log(nums[num]);
}
}
I'm expecting each FizzBuzz to be put into the array instead of the number, and all the array to be printed on the console. But for some specific numbers it doesn't work. When two vales need to be changed consequently, the second one gives some kind of error. What am i missing?
Thanks for your help!