iOS Swift Collections and Control Flow Control Flow With Loops Working With Loops

John Gould
John Gould
1,028 Points

retrieve value from array

I am having trouble figuring out how to retrieve the values from the array

loops.swift
let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0

while counter < numbers.count {   
  counter += 1
  sum = numbers + counter 
}
Daniel Smith
Daniel Smith
10,172 Points

make sure to return the sum at the end of your function, also remember that your sum isn't number +counter. sum+=number. that way the counter number doesnt get added into your sum