Triangle
let row = 1;
let print = “#”;
while (row<8) {
console.log(print);
row = row + 1;
print = print + “#”;
}
FizzBuzz – This one could be a bit tricky because of the execution flow. You need to make sure that you either put the condition that a number should print fizzbuzz if it is divisible by 3 and 5 first in the if statements, or explicitly state that Fizz and Buzz should be printed if a number is ONLY divisible by 3 and 5 respectively. I showed the latter in this case.
let row = 1;
let print = “#”;
while (row<101) {
if (row%3==0 && row%5!==0) {
console.log(“Fizz”);
}
else if (row%5==0 && row%3!==0) {
console.log(“Buzz”);
}
else if (row%5==0 && row%3==0) {
console.log(“FizzBuzz”);
}
else {
console.log(row);
}
row = row + 1;
}
Chessboard – This one took a bit of research. To fulfill the last part of the assignment of allowing the chessboard to change in size I made it so you can change the dimension variable to whatever whole number you wanted it to be. I wanted to write it so it prompted a user to add the number for themselves, but I learned that the prompt function is not supported by ATOM. Otherwise, you can turn the dimension variable into a number (from a string) with the Number function and make it so you get a printout based on whatever the user inputs (as long as they add whole non-negative numbers
)
let dimension = 8;
let counter = 1;
let subcounter = 1;
let array = [];
let print = “#”;
while (counter<=dimension) {
if (counter%2!==0) {
for(print; subcounter <= dimension; subcounter++)
{
array.push(print);
}
console.log(" " + array.join(’ ‘));
}
else if (counter%2==0) {
for(print; subcounter <= dimension; subcounter++)
{
array.push(print);
}
console.log(array.join(’ '));
}
counter = counter + 1;
}