Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Ken Gerlinger
Ken Gerlinger
2,898 Points

Vendingmachine.swift file is incorrect. Please help me out

Right at the end I have two placeholers. Missed out on that one.

Can someone explain to me what I need to put insider those funcs ?

class FoodVendingMachine: VendingMachine { let selection: [VendingSelection] = [.soda, .dietSoda, .chips, .cookie, .wrap, .sandwich, .candyBar, .popTart , .water, .fruitJuice, .sportsDrink, .gum ] quantity von z.b. .chips entspricht var inventory: [VendingSelection : VendingItem] var amountDeposited: Double = 10.0 // Startguthaben der User

the keyword "required" required init(inventory: [VendingSelection : VendingItem]) { self.inventory = inventory } func vend(_ quantity: Int, _ selection: VendingSelection) throws { <#code#> } func deposit(_ amount: Double) { <#code#> } }

Bruce Röttgers
Bruce Röttgers
18,211 Points

Can you please format that code correctly (markdown cheatsheet)

1 Answer

Try this for the vend method

func vend(selection: VendingSelection, quantity: Int) throws {

        guard var item = inventory[selection] else { throw 

        VendingMachineError.invalidSelection
    }