Menu
Coddy logo textTech

What To Buy

Part of the Fundamentals section of Coddy's JavaScript journey — lesson 77 of 77.

challenge icon

Challenge

Medium

Write a function named analyzeBudget that:

  1. Takes three arguments: a list of prices, a list of item names, and a budget per item.
  2. Prints:
    • A list of items you can afford.
    • The total cost of the affordable items.
    • The number of items out of budget.

Example:
For prices = [10, 20, 5, 15], items = ["Notebook", "Pen", "Eraser", "Bag"], and budget = 10, the output should be:

Affordable items: "Notebook", "Eraser"
Total budget needed: 15
Items out of budget: 2

Try it yourself

function analyzeBudget(prices, items, budget) {
    // Write code here
}

All lessons in Fundamentals