3.8 Iterations Homework in JavaScript
Complete the 4 tasks below as homework:
- Uncomment the base code so you can work on adding what you need to produce the correct outputs
- Use
console.log()to display outputs - Some blanks (
_) need to be replaced with numbers or code - Important!!! Under each JavaScript hack, be sure to add an image or screenshot of your outputs in console
- Have fun!
🧩 Task #1
Write a for loop that prints the numbers 1 through 10.
// for (let i = _; i <= _; i++) {
// console.log(_);
// }
🧩 Task #2
Write a while loop that prints the even numbers between 2 and 20.
// let num = _;
// while (num <= _) {
// console.log(_);
// num += _;
// }
🧩 Task #3
Make the following shape using iteration loops with the symbol *:
*
**
***
****
*****
// let stars = "";
// for (let i = _; i <= _; i++) {
// stars += "*";
// console.log(_);
// }
🧩 Task #4
Use a loop to calculate the sum of all numbers from 1 to 100, and print the result.
// let sum = _;
// for (let i = _; i <= _; i++) {
// sum += _;
// }
// console.log("The sum is:", _);