Chapter 25 - Protocol extension practice?

Hi everybody,

When I read Challenge 1 of Chapter 25.
I read this:

When on clearance, food items are discounted 50%, clothes are discounted 25% and
electronics are discounted 5%.

food is Discountable ?

but in the correction it’s whitout the Protocol Discountable :

struct Food: Taxable {
** let name: String**
** var msrp: Double**
** var clearance: Bool**
** let expirationDate: (month: Int, year: Int)**

** let taxPercentage = 0.075**


** var adjustedMsrp: Double {**
** return msrp * (clearance ? 0.50 : 1.0)**
** }**

** var description: String {**
** return “(name) - expires (expirationDate.month)/(expirationDate.year)”**
** }**
}

Is it normal ?

Greg

Hi @gregoirejacquin,
I hope this has been updated and fixed in the updates to the book.

While thinking about this, here’s a few tips from me,
Not everything has an expiry date, so having expiry printed in the description is not a good idea.

Also you can play with the idea of using Protocols as behaviours, which include specific properties and functions to the items.

cheers,

Jayant

Hi @jayantvarma,

Thank you for the answer. But I think there is an error on the challenge text or an error on the code. Nothing naughty but I wanted to understand why. In that case food item not discountable.

:wink:

Hi @gregoirejacquin,
Do you have the latest version of the book?

I think you are referring to the code, not the book. Yes the code has the protocol Taxable, not Discountable.
I guess one of the authors can get back to you on this as to why they did this or if it was a simple error.

cheers,

Jayant

Thank you, take the time for this topic:

Here is the story of the book

BOOK

Here is the correction

CODE

So we never use it adjustedMsrp for the struct Food. While the challenge says Discountable

:wink:

Greg

Oui @gregoirejacquin,
thank you for that, it does seem like a typo / an error.

Perhaps since Food is not discounted, the code works, but yes it does not address the specified criteria.

Thank you for spotting this,

Merci beaucoup,

Jayant

This topic was automatically closed after 166 days. New replies are no longer allowed.