Programming in Kotlin: Fundamentals

Aug 9 2022 · Kotlin 1.6, Android 12, IntelliJ IDEA CE 2022.1.3

Part 3: Functions & Nullability

24. Challenge: Work with Functions

Episode complete

Play next episode

About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 23. Return Data From Functions Next episode: 25. Conclusion

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Heads up... You've reached locked video content where the transcript will be shown as obfuscated text.

To really master functions, I've prepared two challenges for you. And the first one, you have to create a function which takes in two parameters, the first and the last name. Then it has to return the length of the full name. Live the last name as an empty string by default, as some people don't have one. And the second challenge you have to overload the initial function to accept a middle name because some people have one. Then use those two functions to print out the length of two names. Remember to use named arguments when needed when calling function. That's it. Now pause the video and try to solve the challenges. Then once you done hit the play button to check out my solution. (upbeat music) Start off by declaring the function as follows. This function is pretty simple, it sums the length of these two strings. Then print out the name length by calling the function like so. Run the project and you should see the length. Now for the second challenge overload the function to add a middle name parameter like so. Finally print out the length of the name with the middle name. Run the project and you should see the length of their full name. And that's quite a long name.