Sektion 1. Kapitel 38
single
Challenge: for Loop
Stryg for at vise menuen
Opgave
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.
Løsning
Var alt klart?
Tak for dine kommentarer!
Sektion 1. Kapitel 38
single
Spørg AI
Spørg AI
Spørg om hvad som helst eller prøv et af de foreslåede spørgsmål for at starte vores chat