Iterating over arrays
π Scenario: You are helping a small shop owner who keeps a list of daily sales amounts. They want to find out the total sales for the day by adding all the amounts together.
π― Goal: Build a simple JavaScript program that stores daily sales in an array, then uses a loop to add all sales amounts and finally prints the total sales.
π What You'll Learn
Create an array called
dailySales with the exact values: 100, 200, 150, 50, 300Create a variable called
totalSales and set it to 0Use a
for loop with the variable sale to iterate over dailySalesAdd each
sale to totalSales inside the loopPrint the value of
totalSales using console.logπ‘ Why This Matters
π Real World
Adding up daily sales is a common task in shops and businesses to track earnings.
πΌ Career
Knowing how to loop through arrays and sum values is a basic skill for many programming jobs, especially in data processing and web development.
Progress0 / 4 steps