Laser Locker

7. Display Cart

Screen 3 has our grand total for all of the items in the cart displayed. When the user clicks the checkout button, we are going to take them to screen three and show them their total cost. In order to make this happen, we first have to loop through our entire cart and add up each item. Once we find the sum of the list, we are going to set the text of the label that shows our total, and then set the screen to screen 3; and bingo, we have a working app.

You will need to create a local variable in order to sum up the items in the list. Remember that sum = sum + 5; would take the value of whatever is stored in sum and add 5 more to it (you could also use the shorthand sum += 5;).
Hint

The value of i in a for loop tracks the same way an index value does in a list. Meaning for every time a loop iterates, i follows the same value that each new item in a list would. If we can then use that value of i to move through list and update sum, then we have the grand total.

Next
Back