Challenge: for Loop
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Β 4. ChapterΒ 2
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 1.67
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Β 4. ChapterΒ 2
single