Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

Pema Thinley
Pema Thinley
1,504 Points

function

WHAT IS WRONG WITH THIS CODE ? IT DOES NOT SHOW ANY ERROR BUT IT DOES NOT EXECUTE AS WELL.

func costOfCarpetHaving(length len: Int, width wd: Int, carpetColor color: String)-> Int {

var price = 0

let areaOfRoom = len * wd

switch color {
case "red": price = areaOfRoom * 1
case "blue": price = areaOfRoom * 2
case "white": price = areaOfRoom * 3
default: price = 0

} return price }

costOfCarpetHaving(length: 12, width: 5, carpetColor: "white")

2 Answers

Thomas Dobson
Thomas Dobson
7,511 Points

Hi Pema,

Your code is executing fine. Is there a code challenge your having issues with, or perhaps did your Xcode crash? Quit Xcode entirely and reopen everything to see if that fixes it.

Your function call is returning 180 for me :)

func costOfCarpetHaving(length len: Int, width wd: Int, carpetColor color: String)-> Int 
{

   var price = 0

   let areaOfRoom = len * wd

   switch color 
   {
   case "red": price = areaOfRoom * 1
   case "blue": price = areaOfRoom * 2
   case "white": price = areaOfRoom * 3
   default: price
   } 

   return price 

}

costOfCarpetHaving(length: 12, width: 5, carpetColor: "white") //returns 180