Pizza Shop Lab
Lab 9 Pizza Shop
0 / 31
Lab progress

iOS App Development

Build a pizza order screen.

The user builds a pizza and a total price updates as they tap. The price function is written for you. You work out what variables it needs, then build the controls that feed it.

  1. Read the price function
  2. Plan your variables here
  3. Write the code in Playground
  4. Run it in Playground
Step 1

Read the price function

Don't type it. It's already in your starter code below. Just read it.

Step 2

Plan your variables

0 / 7 rows

The function uses six variables that don't exist yet, and your receipt needs a seventh. Work out each one before you write any code. The first row is done for you.

VariableTypeStarting valueControlCorrect

How to tell: if pepperoni { with nothing after it means it's already true or false. size == "Small" compares it to text. Double(quantity) converts it from a whole number.

Steps 3–6

Write your code

0 / 18 checks

Write your code here. The checks update as you type.

ContentView.swift
Step 7

Run it in Playground

Every check above passing means your code has the right pieces. It does not mean the app works. Only Playground can tell you that. Copy and paste your code into a new Playground app to make sure it works.

Do this now, before Step 8

Even if you wrote your code in Playground the whole time, run it again now that everything is connected.

  1. Check that all 18 boxes above are green.Scroll up to Steps 3–6. If any check is still open, fix it first. Do not paste until the counter says 18 / 18.
  2. Hit Copy on the editor above.It copies everything, so you don't miss a line.
  3. Open Swift Playground and make a new App.Not SwiftFiddle. SwiftFiddle only prints text and cannot draw a screen.
  4. Select everything in ContentView.swift and paste over it.Replace the whole file. Do not paste underneath what is already there.
  5. Press Run and watch the App Preview.Red errors? Read the first one, fix it, run again. Fix them from the top down.
  6. Tap every single control.The total should move when you change the size, each topping, the quantity, and delivery. If one does nothing, you forgot a $.

Not working? Paste your code back into the editor above so the checker can look at it. The red notes will tell you what is missing.

Step 8

Test your app

0 / 6 match

Your app has the right pieces, but it could still add up wrong. Set your controls to each row below and check the total against the answer. Tick the box when yours matches.

If a row doesn't match

Only the size rows are wrong
Your Picker words don't match the function. "small" is not "Small", capital letters included.
Rows 1–3 are right, rows 4–6 are wrong
It's the quantity. Check that price = price * Double(quantity) is still there and still comes after the toppings.
A row is off by exactly $4.00
That's the delivery fee. It gets added after the quantity multiply, not before.
Every single row is $4.00 too high
Your delivery starts as true. It should start as false.
A row is off by a topping price
A toggle is wired to the wrong variable. Check each isOn: against the function.

If you finish early

Stuck?

ProblemCheck this
Cannot find '___' in scopeThat @State line is missing, or spelled differently
The size never changes the priceYour Picker words don't match the function. "small" is not "Small"
The total never changes at allYou wrote total instead of total()
Cannot find 'total' in scopeThe function is outside the struct. It goes inside, after body
A control shows but does nothingYou forgot the $
Cannot convert value of type...A starting value is the wrong type. Check your Step 2 table
Right at 1 pizza, wrong at 3Don't retype the function. Compare yours to Step 1 line by line