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

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