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 trialNicholas Moore
1,117 PointsIn this challenge, I am confused on what exactly the "multiplier" name is and does.
I understand what "for loops" do, but in this case I am very confused on what the question is asking. And what is the name in the loop?
// Enter your code below
var results: [Int] = []
for multiplier in 1...10 {
multiplier * 6
}
results.append(multiplier)
1 Answer
Simon Di Giovanni
8,429 PointsOk so, the word 'multiplier' is the name of a TEMPORARY constant that is created, that is used only in the 'for' loop.
For example, multiplier could be named 'bananas', and the result would be the same!
It's just a NAME given to the value that you are iterating through.
So basically, what happens is the loop starts at 1, and assigns 1 to 'multiplier'. It then goes into the loop and does your code, which is multiplier(which is 1) * 6.
Then the for loop has finished, so multiplier IS DELETED.
The loop then starts again! Multiplier becomes 2, then multiplier(which is 2) * 6.
It then keeps repeating this until it gets to the last value you've specified, which is 10.
Hopefully this makes sense. If it doesn't, please let me know.
Nicholas Moore
1,117 PointsNicholas Moore
1,117 PointsYes ! Thank you that makes perfect sense. But then my code is not working. It is saying I have βmultiplierβ as an unresolved identifier, and same as the multiplication sign.
Simon Di Giovanni
8,429 PointsSimon Di Giovanni
8,429 PointsSorry for the late response!
Your βresults.append(multiplier)β is being called outside of the for loop. Remember - multiplier ONLY exists in the for loop!
What you could write, is this - results.append(multiplier * 6)
Making sure that itβs INSIDE the for loop