Popcorn Hacks on Iterations in JavaScript
Instructions:
Complete the exercises below in JavaScript.
You can run and test your code in a JavaScript environment.
Exercise 1: Counting with a For Loop
Write a JavaScript for loop that prints all numbers from 1 to 10.
Example:
Output:
1
2
3
…
9
10
Exercise 2: Sum of Numbers
Write a function in JavaScript to calculate the sum of all numbers from 1 to n using a loop.
Example:
Output: 15 (because 1 + 2 + 3 + 4 + 5 = 15)
Exercise 3: Looping through Arrays
Write a JavaScript program to iterate through an array of names and print each name.