Is this functions workout correct? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Is this functions workout correct?

Functions w/ Return Values Exercise: Verbing Your Noun Write a function that returns a sentence like “Row, row, row your boat” when given a verb and a noun argument. The function should look like this when you call it: let line = openingLine(verb: "Row", noun: "Boat") func makeASentenceWithA(verb: String, noun: String) -> String {     return "\(verb), \(verb), \(verb) your \(noun)." } makeASentenceWithA(verb: "row", noun: "boat") This particular line is what throws me off: let line = openingLine(verb: "Row", noun: "Boat") Is this correct? I'm a little confused about this challenge. What is it telling me?

8th Aug 2018, 6:45 AM
Ran9
Ran9 - avatar
7 Answers
+ 1
No problem. Just happy to help you out. I recognize the lesson you’ve submitted. It’s from Intro to App Development with Swift. It’s a great course, and I recomend that you push through. Some things where they only scratch the surface, will be explained later. It won’t hold your hand, as you’ll find out at later excercises. I advice you to learn from several sources at once. There’s a youtube series by iBrad that can help you if you get completely stuck, though.
9th Aug 2018, 12:12 PM
Håkon T
Håkon T - avatar
+ 1
This doesn’t look correct. To fix this, you can either rename your function to «func openingLine», OR you should change this line: let openingLine = makeASentenceWithA(verb: "Row", noun: "Boat") Notice that I changed «let line» into «let openingLine» instead.
8th Aug 2018, 8:47 PM
Håkon T
Håkon T - avatar
+ 1
It seems to me like you’re more confused to why we have functions in the first place. I’d recomend reading more about functions from several sources for clarity. The gist of it, however, is pretty simple. Functions should be considered as a piece of code that is reusable. The main benefit should be that it saves us both time and lines of code, while also being easy to read. This makes your intention behind the specific code clearer as well. «let line» is simply a constant which we choose to contain the function in this case. Although, it’s visible in the playground, you won’t be able to call the function correctly, unless it’s contained in a constant or a variable. This will throw an error that the function was unused.
9th Aug 2018, 7:28 AM
Håkon T
Håkon T - avatar
+ 1
I appreciate your long response. thanks for taking time from your day. I totally get why functions are used. I have been taking multiple courses using multiple apps, sites, and books. I’m doing cascading lessons to help with memory and understanding the content in different delivery. I just didn’t get why they put let line before the function. This particular lesson (not Sololearn) is the only lesson ive seen yet that keeps putting stuff like let line = before the function and its throwing me off. I thought to call a function you simply write the function name followed by ().
9th Aug 2018, 7:52 AM
Ran9
Ran9 - avatar
+ 1
spot on, thanks alot!
9th Aug 2018, 12:16 PM
Ran9
Ran9 - avatar
0
Im struggling with: let line = openingLine(verb: "Row", noun: "Boat") I think the "let line" is the part the throws me off. why is it there? Is it just saying the line: openingLine(verb: "Row", noun: "Boat") is a constant line that reads as follows i.e. openingLine(verb: "Row", noun: "Boat") ? I may be overthinking it but I don't get why they bother saying, "...the function should look like the let line" if "let line" part isn't in the function. It throws me off. let line = openingLine(verb: "Row", noun: "Boat")
9th Aug 2018, 2:57 AM
Ran9
Ran9 - avatar
0
Is the correct? func openingLine(verb: String, noun: String) -> String { print("Row, \(verb), \(verb) your \(noun).") return "Row, \(verb), \(verb) your \(noun)." } openingLine(verb: "row", noun: "boat") ***please ignore print and return unless you have some advice about using both at the same time. im using both because I'm going back and forth between Xcode and Sololearn playgrounds. I'll throw in my other variation of the above function. func makeASentenceWithA(verb: String, noun: String) -> String { print("Row, \(verb), \(verb) your \(noun).") return "Row, \(verb), \(verb) your \(noun)." } makeASentenceWithA(verb: "row", noun: "boat")
9th Aug 2018, 5:16 AM
Ran9
Ran9 - avatar