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 Swift 2.0 Functions Function Parameters Default Values

Kjetil Korsveien
Kjetil Korsveien
1,713 Points

Xcode gets errors with this code example!

// Default Values

func carpetCostCalculator(length lenght: Int, width: Int, carpetColor: String) -> Int { // Grey Carpet - 1 USD /sq ft // Tan Carpet - 2 USD /sq ft // Blue Carpet - 4 USD /sq ft

let area = calculateArea(lenght, widht: widht)

var price = Int ( error: expected member name or constructor call after type name)

switch carpetColor {
case "grey":
    price = area * 1 (error: No (dot) candidates produce the expected contextual result type Int.Type)
case "tan":
    price = area * 2 (error: No (dot) candidates produce the expected contextual result type Int.Type)
case "blue":
    price = area * 4 (error: No (dot) candidates produce the expected contextual result type Int.Type)
default:
    price = 0 (error: Cannot assign value of type Int to Int.Type)

}
return price (error: Cannot convert return expression of type Int.Type  to return type Int)

}

carpetCostCalculator(length: <#T##Int#>, width: <#T##Int#>, carpetColor: <#T##String#>)

I get the error: expected member name or constructor call after type name

2 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

You have typos here and there throughout your code. In some places you've written "lenght" instead of "length". In other places you've written "widht" instead of "width". I'd advise first going through your code and looking for places that you've inadvertently reversed the t and h in your variable names.

Kjetil Korsveien
Kjetil Korsveien
1,713 Points

OK i did some typos and Xcode had also crashed because of a bug. Everything is fine now :) . Note to self: "Pay more attention to details....