Plenty of π
Module 4: Control Flow – Conditionals and Loops
Lab: Number Properties and Loop Control

Write a program that takes a number (e.g., up to 20). Iterate from 1 to this number. Print whether each number is even or odd. Additionally, skip printing numbers divisible by 3, and stop the loop entirely if the number 15 is reached.

Tasks to Complete:

  • Define a variable `limit` (e.g., set it to 20).
  • Use a `for` loop to iterate from 1 up to `limit` (inclusive).
  • Inside the loop, first check if the current number `i` is equal to 15. If it is, use `break` to exit the loop.
  • Next, check if `i` is divisible by 3 (i.e., `i % 3 === 0`). If it is, use `continue` to skip the rest of the current iteration.
  • If the loop hasn't broken or continued, determine if `i` is even or odd (`i % 2 === 0` for even).
  • Print a message indicating the number and whether it's even or odd (e.g., "1 is odd", "2 is even").

JavaScript Sandbox

Output will appear here...

JavaScript execution is sandboxed. Output from `console.log()` and errors will appear above.