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 trialboris said
3,607 PointsWhenever I try to run my program it crashes.
Can somebody please help me fix these crashes or atlas explain what is causing them.
Here is my code:
class Product {
let title: String
var price: Double = 0.0
init(title: String, price: Double) {
self.title = title
self.price = price
}
func discountedPrice(_ percentage: Double = 10.0)-> Double {
return price - (price * percentage / 100)
}
enum Size {
case Small, Medium, Large
init() {
self = .Medium
}
}
}
class Clothing: Product {
var size = Size()
override func discountedPrice(percentage: Double)-> Double {
return price - (price * percentage / 100)
}
} // <-- I added the closing } Steve. :-)
var tshirt = Clothing(title: "Tshirt", price: 500)
10 Answers
Steve Hunter
57,712 PointsThere doesnt seem much wrong with that except you haven't closed your Clothing
class before you declare your variable. Add another closing brace above the tshirt
declaration.
Let me kow if that doesn't get it sorted.
Steve.
boris said
3,607 PointsIt is still crashing, I tried updating the software even using the downloaded file and neither worked. I think it is a bug.
Steve Hunter
57,712 PointsWhat error are you getting?
boris said
3,607 PointsExtraneous '_' in parameter: 'percentage ' has no keyword argument name
Steve Hunter
57,712 PointsDelete the _ then?
boris said
3,607 PointsI tried it still crashes
Kamran Ismayilov
5,753 PointsI think it is because the lately update. It says 'Expected Declaration' having the same issue
import UIKit
class Product {
var title: String
var price: Double = 0.0
init(title: String, price: Double) {
self.title = title
self.price = price
}
func discountedPrice(percentage: Double) -> Double {
return price - (price * percentage / 100)
}
}
enum Size {
case Small, Mediu, Large
init() {
self = .Small
}
}
class Clothing: Product {
var size = Size()
override func discountedPrice(percentage: Double) -> Double {
return price - (price * percentage / 100)
}
let tshirt = Clothing(title: "T-Shirt", price: 344.99)
let quadcorpet = Product(title: "Quadcorpet", price: 23.99)
boris said
3,607 PointsSo do you think I should just wait for it to be fixed.
Van Sanders
16,087 PointsI'm getting the same error. I noticed that Xcode only freaks out when I try to set a default value for the 'percentage' argument. The code challenge following this video doesn't seem to like it either...
boris said
3,607 PointsDo you know anywhere where I can downgrade Xcode?
Steve Hunter
57,712 PointsI think you can remove updates inside the App Store; it lists the updates you've applied - I think you can disapply them there. Never tried, though.
Steve.
boris said
3,607 PointsI won't show all my updates it just shows two. Do you think I could get it from Time Machine?
boris said
3,607 PointsI asked a question on Stack Overflow maybe someone there knows how to fix it.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI added the closing brace and a comment in your code.
What errors are you seeing in your code?