iOS Swift Collections and Control Flow Control Flow With Loops For In Loops

Please I need help solving part 2

Please advise me as to what I am missing.

// Enter your code below
var results: [Int] = [1,2,3,4,5,6,7,8,9,10]

let multiplier = 6 

for multiplier in 1...10{
        results.append(multiplier * 6)

1 Answer

Magnus Hållberg
Magnus Hållberg
16,953 Points

The results array should be empty at start, the append method inside the body of the loop is supposed to do that job. Also delete the multiplier constant you created and you should be good to go. When creating a for loop you automatically get a variable with the job of carrying the value of the range for each iteration, in this case it's named multiplier. Multiplier will at first have the value 1, then 2 and so on. Maybe I'm kicking in open doors for you, if so I'm sorry for over explaining things.

var results: [Int] = []
for multiplier in 1...10 {
  results.append(multiplier * 6)

Thank you very much. That was very helpful.