Sectionย 1. Chapterย 38
single
Challenge: for Loop
Swipe to show menu
Task
Swipe to start coding
Imagine you are buying several items in a shop. Each item costs the same amount, and you want to calculate the total cost of all items.
- Initialize
totalCostto0. - The loop should start with
i = 0and run whilei < quantity. - Add
itemPricetototalCostinside the loop. - Return
totalCostat the end of the method.
Solution
Everything was clear?
Thanks for your feedback!
Sectionย 1. Chapterย 38
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat