Learn Courses My Dashboard

Lesson 9 challenge

After completing lesson 9 fairly confidently, I was confused as to why I still had an error. I checked Chris’s answer key and saw that his code was the same as mine, other than variable names. I even copy and pasted Chris’s code into my playground but still had the error. For the lesson 9 challenge, the number of people variable is supposed to be an integer - however, Xcode does not allow a Double to be divided by an integer. I am aware of type casting from Java but can’t seem to understand if there is still something I’m missing or if I should simply change the numPeople variable into a Double for this challenge?

The solution should be fixed soon. It should say:

return totalWithTax / Double(numPeople)

Also be careful when naming your variables. Shortening them by saying totalWTax might make sense to you now but when you come back to your code months later (or someone else reads your code), it may not be clear.

1 Like