Message "Expected '}' at end of brace statement"

Hi. I am currently following Apple's swift course. However, I get an error saying "Expected '}' at end of brace statement" and I don't really understand why ? Can someone explain why and eventually correct the code ? Thanks !

var question2 = question
let lowerQuestion2 = question.lowercased()
"hello" == "Hello"
func responseTo(question: String) -> String {
    if question.hasPrefix("hello") {
        if lowerQuestion2.hasPrefix("hello") {
            return "Hello there"
        } else {
            return "That really depends"
    }
}
Answered by Kwiky in 721622022

Even if I haven't found a solution to the error, the code itself was wrong. Here's the solution.

var question = "HELLO"
let lowerQuestion = question.lowercased()
func responseTo(question: String) -> String {
    if lowerQuestion.hasPrefix("hello") {
        return "Hello there"
        } else {
            return "That really depends"
    }
}
Accepted Answer

Even if I haven't found a solution to the error, the code itself was wrong. Here's the solution.

var question = "HELLO"
let lowerQuestion = question.lowercased()
func responseTo(question: String) -> String {
    if lowerQuestion.hasPrefix("hello") {
        return "Hello there"
        } else {
            return "That really depends"
    }
}

You have four left braces in your code and only three right braces. Each left brace needs a matching right brace.

Add a right brace after the second return statement.

func responseTo(question: String) -> String {
    if question.hasPrefix("hello") {
        if lowerQuestion2.hasPrefix("hello") {
            return "Hello there"
        } else {
            return "That really depends"
} // Add the brace here to close the else block.
    } // End the outer if block
} // End of func

Thanks for the answer @szymczyk. I still have the same problem, no luck for me...

Message "Expected '}' at end of brace statement"
 
 
Q