Monday, March 27, 2023

Intro To App Development - Coding Happy - Getting Started With Functions

Students in my Intro to App Development class are learning about functions in Swift, how to declare a function, how to call a function, how functions can make program code more modular, and help programmers to reuse code for repetitive tasks.

What better way to practice functions than to look at song lyrics and think about how the chorus of a song repeats and can be put into code.

Check out the video below if you are unfamiliar with this popular song.

Coding "Happy" by Pharrell Williams


Click the link above to see the lyrics for the song.

Declaring and Calling Functions in Xcode
We declared functions to represent each verse of the song including the chorus and then created a program in Xcode to efficiently print the song lyrics by called the functions, saving us time and effort as the chorus and one of the verses repeat several times.

We also practiced different ways to print strings in our code as you can see in the snippet of code below.




No comments:

Post a Comment