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 trialMatti Helenius
421 PointsI'm having problem understanding the code lesson what im suppose to on ARRAYS. Please help.
Hey!
I'm trying to code this array lesson, im not sure what im SUPPOSE TO DO. could someone help me understand so I could try to get pass it?
Challenge Task 2 of 2
Inside the body of the loop, we're going to use the multiplier to get the multiple of 6. For example, if the multiplier is 1, then the multiple is 1 times 6, which is equal to 6.
Once you have a value, append it to the results array. This way once the for loop has iterated over the entire range, the array will contain the first 10 multiples of 6.
Heres my code;
// Enter your code below
var results: [Int] = [0,1,2,3,4,5,6,7,8,9]
for multiplier in 1...10
{
var results = ("\(multiplier * 1)")
}
Thanks in advance!
Halyna Buriachenko
Courses Plus Student 1,868 Pointsvar results: [Int] = [6,12,18,24,30,36,42,48,54,60]
for multiplier in 1...10{
print("\(multiplier) times 6 is equal to \(multiplier * 6)")
}
Hey! You have task to get the multiple of 6. In your code you're multiplying times 1! And then you should append results(1*6= 6, 2*6=12, 3*6=18, 4*6=24 ...) to the array at the very beginning.
1 Answer
Jeff Tabaka
1,235 Pointshey man.
Just finished this exercise after trying a few things, looking up others, and failing a few times. BUT I FINALLY GOT IT!!
first... take out the numbers you added to the "var results" line second... delete what you added in the body
it should now look like the post from Matt, or how it was when you started the second part of the challenge.
third...do this...
var results: [Int] = [] for multiplier in 1...10 { let multiplier = multiplier * 6 results.append(multiplier) }
thats it!!!!!!!!!
Matt Skelton
4,548 PointsMatt Skelton
4,548 PointsHey Matti,
So for this task, the challenge is to use the for loop you created in the first part of the code challenge to append the first 10 values of the 6 times table into your results array.
So initially, you start off with your empty for loop, like so:
If you remember from the video on for loops, for each iteration through the loop, we will increment the value of 'multiplier' from an initial value of 1 all the way through to 10.
Knowing this, we want to programmatically add the first 10 values of the 6 times table to our array. We can append values to our array using the .append() method, whilst the parentheses contain a given value. The value we pass into those parentheses can be a hard coded integer value OR an expression that equates to an integer value. We want to pass in a short expression that returns the current value of our multiplier, multiplied by 6.
Also just to clarify, within the body of your loop, you won't need to use to var keyword as your results array has already exists.
Give that a try and let me know how you get on!