Triangle Loop (this did not work for me)
let a = ‘#’;
while (a.length < 8){
console.log(a); a+=a;
}
FizzBuzz
let i=1;
while (i < 100){
if(i % 3 == 0 && i % 5 == 0){
console.log(“FizzBuzz”); i++;}
else if (i % 3 == 0){
console.log(“Fizz”); i++;}
else if(i % 5 == 0){
console.log(“Buzz”); i++;}
else{
console.log(i); i++;}
}
Chess Board
I could not solve this one on my own. I had to look at the solution. I started out like this:
let size = 8;
let hash = ‘#’;
let col = 0;
let row = 0;
When I looked at the solution, I could see I was thinking about this sort of correctly, so I feel good about that. But I now understand I could have created the column and row grid using ‘if’ statements.
Quick update on chess board; I’ve been learning about nested loops and how they work. In this case, the column and row variables start out at zero and work their way up the “less than size” variable. I added some additional text output per loop so I can try to understand how and when each variable increments. If size = 4, the inner and outer loops execute a total of 12 times to generate the chessboard:
let size =4;
let board = “”;
for(let y=0; y<size; y++){
for(let x=0; x<size; x++){
if((x+y) % 2 == 0){
board += “_”;
console.log(“y = " + y + " " + “x = " + x);
}else{
board +=”#”;
console.log("x = " + x + " " + "y = " + y);
}
}
board += “\n”;
}
console.log(board);

What I still don’t understand is how the col/row variables go back to zero after the increment. But I think the whole process starts over for each col/row variable until BOTH reach “less than size” at the same time.