Challenge
Let's practice!
Swipe to start coding
Lily went to the shop to buy some clothes. It was the sales day so all the clothes she bought were at discount. Let’s calculate the total discount she got.
We have two arrays of the same length (6): prices and sales. The first array stores prices (in dollars) for Lily’s clothes and the second one stores discounts (in percent, 0.1 means that the thing has a 10% discount) for the corresponding clothes.
You should:
- Use for loop to go through the arrays, don't forget to open curly brackets.
- Calculate the discount for each thing by multiplying the corresponding elements of two arrays and store the result in the variable
discountForEach
.
- To find the sum of all discounts, add variables
discountForEach
andtotalDiscount
, and store the result in the variabletotalDiscount
.
- Close curly brackets.
- Print the variable
totalDiscount
.
Please, don’t forget to type the semicolon at the end of the lines.
Oplossing
Bedankt voor je feedback!
single
Vraag AI
Vraag AI
Vraag wat u wilt of probeer een van de voorgestelde vragen om onze chat te starten.
Awesome!
Completion rate improved to 3.33
Challenge
Veeg om het menu te tonen
Let's practice!
Swipe to start coding
Lily went to the shop to buy some clothes. It was the sales day so all the clothes she bought were at discount. Let’s calculate the total discount she got.
We have two arrays of the same length (6): prices and sales. The first array stores prices (in dollars) for Lily’s clothes and the second one stores discounts (in percent, 0.1 means that the thing has a 10% discount) for the corresponding clothes.
You should:
- Use for loop to go through the arrays, don't forget to open curly brackets.
- Calculate the discount for each thing by multiplying the corresponding elements of two arrays and store the result in the variable
discountForEach
.
- To find the sum of all discounts, add variables
discountForEach
andtotalDiscount
, and store the result in the variabletotalDiscount
.
- Close curly brackets.
- Print the variable
totalDiscount
.
Please, don’t forget to type the semicolon at the end of the lines.
Oplossing
Bedankt voor je feedback!
Awesome!
Completion rate improved to 3.33single