scrimba
Frontend Career Path
Essential JavaScript concepts
JS Mini Projects
For loop Break and Continue
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

For loop Break and Continue
AboutCommentsNotes
For loop Break and Continue
Expand for more info
index.js
run
preview
console
/* 
Below is an array of objects representing expenses and refunds.
Positive amounts are expenses, negative amounts are refunds.

We want to find out how much money was spent in 2023.
*/

const expensesAndRefunds = [
{ description: 'Groceries', amount: 50, year: 2023 },
{ description: 'Electronics', amount: -30, year: 2023 },
{ description: 'Dinner', amount: 40, year: 2023 },
{ description: 'Clothing', amount: 60, year: 2023 },
{ description: 'Entertainment', amount: 25, year: 2023 },
{ description: 'Rent', amount: -500, year: 2024 },
{ description: 'Utilities', amount: 100, year: 2024 },
{ description: 'Books', amount: 20, year: 2024 },
{ description: 'Fitness', amount: 30, year: 2024 },
{ description: 'Gifts', amount: 15, year: 2024 },
]

let totalSpent = 0
const cutoffDate = 2024


console.log(`Total amount spent on items in 2023: $${totalSpent}`)
Console
"Skipping Electronics due to refund"
,
"Reached cutoff date, exiting loop"
,
"Total amount spent on items in November: $175"
,
/index.html
-5:14