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 trialErik Luo
3,810 PointsHow do you append the value to results?
How do i append the value to results? and how come in this challenge there is a Int array(var results: [Int] = []), but when I tried it in xcode, it gave me an error.
// Enter your code below
var results: [Int] = []
let number = 1...10
for multiplier in number {(multiplier * 6)}
results.append()
1 Answer
andren
28,558 PointsYour solution is very close to correct, in fact you have all of the code for the solution written. You can solve the challenge by simply rearranging your code a bit.
To append something to an array you can indeed simply use the .append method, just like you do in your solution, however you need to pass in the value that you want to append as an argument to the method. In addition you have to append the results within the loop, currently your appending code is outside the loop.
If you move it inside the loop, and use the value that is already written in the loop as the argument like this:
var results: [Int] = []
let number = 1...10
for multiplier in number {
results.append(multiplier * 6)
}
Then you will be able to pass the challenge.
Erik Luo
3,810 PointsErik Luo
3,810 PointsOMG, I didn't know you can do that, so close. Thank you!