Hi All,
Super beginner here! I am completing the Module 1 Lesson 7 activity and had a question in regards to the solutions. This is really bugging me and I need to get a clear understanding of this or I’m afraid I’ll run into more confusion later down the line so I need to nip this in the bud now.
When completing the question below, my solution was to create a new variable within the liftOff function to capture the result of fuelLevel - 50. However, when I check the solution for this problem, instead of creating a new variable, Chris used the same variable (fuelLevel) already created and used the mathematical operator -= to get the result of fuelLevel - 50. My question is,
- Is my solution wrong?
- If not, is it okay to do it this way since it will give me the same result in return?
Thanks in advance!
DIRECTIONS
Inside the “liftOff” method, write code that will:
-
• Decrement the fuelLevel property by 50.
-
• Print to the console “We have lift off!”.
-
• Print the current fuelLevel to the console.
-
• Use a message like “Current Fuel Level at: X” where X is the actual value of the fuelLevel property.
-
• Hint: Substitute dynamic values into strings using “(fuelLevel)” inside the string.
CHRIS SOLUTION:
func liftOff() {
// Decrement by 50
fuelLevel -= 50
// Print statements
print("We have lift off!")
print("Current Fuel Level at: \(fuelLevel)")
}
MY SOLUTION
func liftOff() {
var currentFuelLevel = fuelLevel - 50
print("We have lift off!. Current fuel level at \(currentFuelLevel)")
}