Extracting Code to Functions
The logic you coded into bounty-board in Chapter 3 is sound, but it would be a better practice to organize it using functions. Your first task is to reorganize your project to encapsulate the logic you have already written to set the text of the bounty board in a function. This will set the stage for adding new features to bounty-board.
Does this mean you are going to delete your code and type the same logic in a different way? Perish the thought. IntelliJ will help you group your logic into a function easily.
Begin by opening your bounty-board project. Make sure the file Main.kt is open in the editor.
Next, select the conditional code that you defined for generating the quest message. Click and ...
Get Kotlin Programming: The Big Nerd Ranch Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.