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 trialNader Adam
2,863 Pointswhat is the wrong here
// Enter your code below var results: [Int] = [] for multiplier in 1...10{
results[multiplier-1] = (multiplier * 6) }
// Enter your code below
var results: [Int] = []
for multiplier in 1...10{
results[multiplier-1] = (multiplier * 6)
}
2 Answers
jcorum
71,830 PointsClose!
var results: [Int] = []
var multiplier = 6;
for i in 1...10 {
results.append(i * 6)
}
You need to create the multiplier variable outside the loop and give it a value, and then use it in the loop. You also need a loop counter (the i in the code above).
Jennifer Nordell
Treehouse TeacherI think your code might actually work. But it's not what they're looking for. They want you to use the .append function. Try this out:
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
results.append(multiplier * 6)
}
Nader Adam
2,863 Pointsthanks a lot
jcorum
71,830 PointsJennifer's right, the code works, but not in the challenge. The editor won't accept it. I tried. When it says
define a constant that temporarily stores the value in the iteration process. For the loop you're writing, name this constant multiplier"
you won't get past Task 1 unless there's a multiplier
declared. It's interesting, but I just noticed that in the code I sent you multiplier
is a var
not a let
, so the editor should have rejected my code as well!
Christian Birmele
1,106 PointsThank you, this worked!
Nader Adam
2,863 PointsNader Adam
2,863 Pointsthanks a lot
Nader Adam
2,863 PointsNader Adam
2,863 Pointsthanks