Day 5 — Loops and iteration

Homework

Problem 1 Part 1
for (let i = 1; i <= 50; i++) {
  if (i % 3 === 0 && i % 5 === 0) {
    console.log("FizzBuzz");
  } else if (i % 3 === 0) {
    console.log("Fizz");
  } else if (i % 5 === 0) {
    console.log("Buzz");
  } else {
    console.log(i);
  }
}

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 2 Part 2
let n = 1;

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 3 Part 3
while (n * n <= 1000) {
  n++;
}

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 4 Part 4
console.log(n); // 32

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 5 Part 5
for (let i = 1; i <= 5; i++) {
  let row = "";

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 6 Part 6
for (let j = 1; j <= i; j++) {
    row += "*";
  }

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 7 Part 7
console.log(row);
}

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 8 Part 8
const scores = [88, 72, 95, 60, 41];

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 9 Part 9
let max = scores[0];

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 10 Part 10
for (const score of scores) {
  if (score > max) {
    max = score;
  }
}

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).

Problem 11 Part 11
console.log(max);

Reference solution lives in ../js/homework.js (loaded at the bottom of this page).