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 trialGrzegorz Chyb
1,568 PointsTemporary constant inside the loop named wrong?
Hey, it says the name of temp const is wrong. I seriously have no idea what's really the case, but it's not the name for sure.
Thanks in advance
// Enter your code below
var results = [1...10]
for multiplier in results {
results.append(multiplier * 6)
}
4 Answers
Kourosh Raeen
23,733 PointsDon't change the original empty array. Try this:
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
kjvswift93
13,515 PointsYou are close
// Enter your code below
var results: [Int] = []
for multiplier in 1...10{
results.append(multiplier * 6)
}
Grzegorz Chyb
1,568 PointsThanks both of you! It worked but I still don't understand why the results array has to be empty.
Kourosh Raeen
23,733 PointsYou want the results array to contain the first 10 multiples of 6, so we need to start we an empty array and using the loop add those multiples to the array. The first iteration of the loop adds 1 * 6, which is 6, to the array. Then next iterations adds 2 * 6, which is 12, to the array. The last iteration of the loop adds 10 * 6, which is 60, to the array and now you have: [6, 12, 18, 24, 30, 36, 42, 48, 54, 60]
If you start with an array that is not empty then it would not look like that when you are done.
Reed Carson
8,306 Pointsany time you change specific values the challenge has given you it will be wrong. It may be workable code but part of the course is following specific instructions and paying attention to details - very important for coding.