Post

Replies

Boosts

Views

Activity

Beginner question: argument labels
Hi everyone! I'm working my way through Apple's Swift documentation and learning sessions. I've come across an exercise related to argument labels that has me stumped. Here is the function code the task refers to: func score(reds: Int, greens: Int, golds: Int) -> Int {     let pointsPerRed = 5     let pointsPerGreen = 10     let pointsPerGold = 30          let redScore = reds * pointsPerRed     let greenScore = greens * pointsPerGreen     let goldScore = golds * pointsPerGold          return redScore + greenScore + goldScore } let finalScore = score(reds: 5, greens: 3, golds: 3) Now the task is to add an argument label to the function definition so when the function is called it reads as such:  let finalScore = score(withReds: 5, greens: 3, golds: 3) In order to alter the label 'reds' in the function definition to 'withReds' I'd have to alter the references to that label in the function code - but the task says I shouldn't have to do that. Am I missing a trick relating specifically to "with" that means I can change something in the function definition without the function code itself? The addition of "with" has me a bit stumped and I'm not sure what it refers to! Any help would be incredibly appreciated 😊
4
0
1.1k
Nov ’20