Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSebastian Moreno
794 PointsConfusion with the last part
They say that I have to append something to the results, I've checked all the code in swift and it woks by showing all multiples of 6 till 6*10 as asked.
but I don't understand how the append part works here and how im I supposed to use it.
Thanks in advance for the help!
// Enter your code below
var results: [Int] = []
for multiplier in 1...10{
print("\(multiplier) times 6, which is equal to \(multiplier * 6)")
}
3 Answers
andren
28,558 PointsAppending to the array means to add values to it, and to do so you can simply use the append
method found on the array.
Example:
var results: [Int] = []
results.append(5) // You can type pure values
// results is now equal to [5]
results.append(5 + 2) // You can also type equations and other expressions like that
// results is now equal to [5, 7]
The challenge wants you to append the same numbers to the results
array that you are currently printing out in your string, so you already know how to produce the right value. You just need to use the append
method within the loop to actually add it to the array.
lvwdhydynw
6,443 PointsHi Sebastian!
You have to have "results.append()" inside of the for loop. Also, append() method takes 1 argument: what exactly you want to append. However, in your code it takes no argument. Fix these 2 things and it should be alright :)
Sebastian Moreno
794 PointsThank you very much for your kind help, however I still don't magian to solve my issue!
Sebastian Moreno
794 PointsSebastian Moreno
794 PointsI try to append the multiplier name in the results, but it doesn't work, they tell me that once I have a result I need to append it to the results array, but when I do it doesn't work because it says multiplier is not is an unresolved identifier
this is what I have
// Enter your code below var results: [Int] = [] results.append()
for multiplier in 1...10{ print(multiplier * 6) }
if I add inside the append "6+6+6+6+6+6+6+6+6+6" it still tells me that I must Make sure the results array contains the first 10 multiples of 6