Binary operator '+' cannot be applied to operands of type '()' and 'String' error

Hi. I'm getting an error on the index 1 of my code : Binary operator '+' cannot be applied to operands of type '()' and 'String'. The code block is the following

func addDance (_ sentence: String) {

    return addDance(sentence: String) + " and then we dance"

}

The instruction of the exercise I'm doing is the following : «Create a function addDance that takes a string, appends a phrase about dancing (like "and then we dance!" or "but no dancing", according to your taste), and returns the new string.

 Call the addDance function passing in myPlans, and assign the result to friendPlans. »

Perhaps you mean this?

func addDance(_ sentence: String) -> String {
    return sentence + " and then we dance"
}
Accepted Answer
func addDance (_ sentence: String) {
    return addDance(sentence: String) + " and then we dance"
}

what @robnotyou said, plus.

There are several errors here:

  • when you call a func, you need to pass a parameter, not its type
  • so it should be
return addDance(sentence) + " and then we dance"
  • But, calling the func inside itself will cause infinite recursion:
    • you call addDance
    • this will call addDance
    • which will call again addDance
    • and this ad libitum, until crash

.

  • the error means that

addDance(sentence: String) is considered as a func (which would be different from addDance (_ sentence: String) as it has not the exact same signature : _ is missing) with no return type (that's what () means)

// Define and call your function here:

func addDance (_sentence: String) {

    return addDance (sentence) + " and then we go dance"

} ***getting cannot find "sentence" in scope please help. I followed what you helped him out with and still getting the same error

    

    

Binary operator '+' cannot be applied to operands of type '()' and 'String' error
 
 
Q