Ray Wenderlich Fundamentals Course - Part 4
Here we go! Last chapter of the course for fundamentals. This one is a bit longer so may need two entries. Let's go!
Start Time - 17:39
Compound types - e.g. for tuples. This is about information being bundled together.
Value and reference types - we'll be coming to that!
Functions
Start Time - 17:39
Compound types - e.g. for tuples. This is about information being bundled together.
Value and reference types - we'll be coming to that!
Functions
func printPass(grade: Int, pass: Int) {
if grade >= pass {
print("Your grade score of \(grade) has passed! You passed by \(grade - pass).")
} else {
print("Your grade score of \(grade) did not pass!")
}
}
printPass(grade: 72, pass: 50)
I've elaborated on this a bit.
OK, difference between parameter and argument. It's called parameter when declared. When called, and providing values, it is an argument! Cool, that does clarify.
func printHighestGrade(_ grade1: Int, _ grade2: Int) {
print(grade1 > grade2 ? grade1 : grade2)
}
printHighestGrade(44, 56)
Good use of the ternary operator above.
Functions represent tasks or actions. So it is convention to use verbs. Most important thing is staying consistent in the naming.
*Paused for around 15 mins.
Mention of type alias. Use of when calling function to create a new type.
Challenge no problem at all.
So that's all functions done.
Finish Time - 18:31 (37 minutes total)
So all functions done. And all good! Will finish off rest of the chapter tomorrow.
Comments
Post a Comment