FizzBuzz
Okay, so I first wrote this:
for (let i = 1; i < 101; i++) {
console.log(i);
if (i % 3 == 0)
console.log(“Fizz”);
if (i % 5 == 0)
console.log(“Buzz”);
if (i % 3 == 0 && i % 5 == 0)
console.log(“FizzBuzz”);
}
and quickly realized that I was close, but my output was still printing numbers divisible by 3 and 5, so I adjusted the code to this:
for (let i = 1; i < 101; i++) {
console.log(i);
if (i % 3 == 0)
console.log(“Fizz”);
if (i % 5 == 0)
console.log(“Buzz”);
if (i % 3 == 0 && i % 5 == 0)
console.log(“FizzBuzz”);
}
and realized that only printed Fizz and Buzz words, but not the numbers. After 45 minutes after I started (LOL), I realized I needed to incorporate else statements to obtain the correct output and came up with this;
for(i = 1; i <101; i++) {
if (i % 3 == 0) {
console.log(“Fizz”);
}
else if (i % 5 == 0) {
console.log(“Buzz”);
}
else if ((i % 3 == 0) && (i % 5 == 0)) {
console.log(“FizzBuzz”);
}
else
{console.log(i);
}
}
and it worked! Nice lessons learned with this exercise!
Chess Board - after another hour+, I finally got this to work:
board_size = 8;
for(let row = 1; row <= board_size; row ++){
let board = “”;
for(let column = 1; column <= board_size; column ++) {
if ( (row + column) % 2 == 0) {
board += “#”;
}
else{board += " ";
}
}
console.log(board);
}
I did have indentations in my code as best as I could, but didn’t translate here. Anyway, I’ll never be a programmer at this speed!!! LOL