FAQs on the exercise Implementing a Computed Property in an Enumeration
There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
You can also find further discussion and get answers to your questions over in Language Help.
Agree with a comment or answer? Like () to up-vote the contribution!
Create a computed variable property in Vehicle called description that returns a String value.
Here are the description values for each case:
Airplane returns: "This is an airplane"
Boat returns: "This is a boat"
Truck returns: "This is a truck" if isFourWheelDrive is false
Truck returns: "This is a truck with four wheel drive" if isFourWheelDrive is true
The problem:
The code is only accepted if it is an exact copy of the suggested solution. It didn’t matter that my code had the correct logic for returning the truck’s description based on if it’s four wheel drive or not. I had to check the solution and replace my code with the solution before it was accepted.
In other words, this was a task of “guess the exact way someone else did this”.
What is the exact same solution, I’m unable to get it correct. My solution should work but does not match what they are asking for.
enum Vehicle {
case airplane
case boat
case truck(isFourWheelDrive: Bool)
// 1: Create computed value here
var description : String {
switch self {
case .airplane:
return "This is an airplane"
case .boat:
return "This is a boat"
case .truck(let isFourWheelDrive):
if isFourWheelDrive {
return "This is a truck with four wheel drive"
} else {
return "This is a truck"
}
}
}
I found a bug in View Solution mode. There are two the same parts of code, but one of them is not my code. I didn’t use ternary operator, so algorithm has taken the solution code and put it to both sections: my code and solution.
I write code like this, but it can’t pass the first instruction’s code checking. The only code can pass needs to exactly the same as the solution.
enum Vehicle {
case airplane
case boat
case truck(isFourWheelDrive: Bool)
// 1: Create computed value here
var description: String {
switch self {
case .airplane:
return "This is an airplane"
case .boat:
return "This is a boat"
case let .truck(isFourWheelDrive):
if isFourWheelDrive {
return "This is a truck with four wheel drive"
} else {
return "This is a truck"
}
}
}
}
I’ve tried variations of both this (the original logic I wrote which worked two exercises ago) and the ternary in the hint and everything either throws an error, or else is still counted as wrong. How on earth do I pass this exercise/step?
I am unable to get the correct my solution after my logic code following:
enum Vehicle {
case airplane
case boat
case truck(isFourWheelDrive: Bool)
// 1: Create computed value here
var description: String {
switch self {
case .airplane:
return "This is an airplane"
case .boat:
return "This is a boat"
case .truck(isFourWheelDrive: false):
return "This is a truck"
case .truck(isFourWheelDrive: true):
return "This is a truck with four wheel drive"
}
}
}
So I got with NO errors in the console but I am still getting with the error’s message although my code works fine :
ERROR: Did you create a computed variable property with the right name and functionality?