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 trialVictor O'Rourke
2,387 Pointsneed help getting started on this one
I feel like i know the code needed for this just need a push in the right direction. what should i be defining in integars first, the numbers 1...10? then creating a new line for the actual loop with the constant?
// Enter your code below
var results: [Int] = [1...10]
2 Answers
Matthew Long
28,407 PointsYou're correct that we're looping over the range 1...10
. However, you tried doing this in the wrong place. As we go through the loop we're going to append a multiple of 6 into the results array. So this means you aren't going to add anything inside the array directly in your code like you tried. This gave you an error.
Below is the solution to the first part of the challenge to get you started. Let me know if you need help with the next parts!
var results: [Int] = []
let multiplier = 6;
for i in 1...10 {
// code for challenge two
}
Victor O'Rourke
2,387 Pointsi found a different way in another comment that resolved it too! Thanks for such a quick response!! so in this case were actually defining the constant out of the function. didnt learn it that way in the videos yet, but makes sense why i was missing that one :)
Matthew Long
28,407 PointsThe beauty is there are almost always more than one way to solve something! Maybe what you saw was this:
for multiplier in 1...10 {
}
This is actually what the challenge is looking for. So this would complete the challenge but makes less sense to me since this seems like it's saying the multiplier is 1
, 2
, 3
etc where I think of the multiplier as 6
. Maybe I feel this way because they made us use the constant named multiplier
.