What To Buy
Part of the Fundamentals section of Coddy's JavaScript journey — lesson 77 of 77.
Challenge
MediumWrite a function named analyzeBudget that:
- Takes three arguments: a list of prices, a list of item names, and a budget per item.
- 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: 2Try it yourself
function analyzeBudget(prices, items, budget) {
// Write code here
}All lessons in Fundamentals
4Operators Part 2
Logical Operators Part 1Logical Operators Part 2Recap - Simple LogicLogical Operators Part 3Type Coercion7Bill Split Calculator
Welcome MessageCalculating The Tip And Total2Variables
NumbersStringBooleanNaming ConventionsEmpty VariablesRecap - Initialize VariablesConstants3Operators Part 1
Arithmetic OperatorsModulo OperatorArithmetic ShortcutsComparison OperatorsStrict vs Loose EqualityRecap - Simple Math6Basic IO
OutputOutput with VariablesType Conversion - Part 1Type Conversion - Part 2Recap - Till 120Recap - True or False