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 trialAR Ehsan
7,912 PointsUse a for-in loop to print out a "7 times table". Your output should look like this: 1 * 7 = 7 2 * 7 = 14
Confused
for number in 1..<10 {
println("\(number) times 7 is \(number*7)")
}
3 Answers
krilnon
1,458 PointsYour code looks like it is close to what the challenge is asking you to do. The two things that pop out to me are:
1) You are using "times" instead of "*", the times symbol. This sounds like a small detail, but sometimes the challenges do require you to meet their standards of detail. Similarly, you might want to replace is
with =
, since the grading program might be checking for a very specific output including the =
symbol.
2) You are using the ..< "half-closed range" operator to go from 1 to 10. Unfortunately, that operator will stop the range just before the number specified by the right-hand-side operand. So, you can either switch to the ...
operator, or use 11 as the upper bound on your existing range.
Alex Barbato
1,962 PointsHey there! How's this?
This code is essentially saying for the loop to run 1 through 10 times and print out the output of 1 * 7 = 7, 2 * 7 = 14, etc. The (number) just tells the system to use the value for number at that moment.
David Maybach
2,092 PointsTreehouse wants us to think a bit further so the example on the video doesn't provide the exact answer
Your code should look at something like this below
Q: Use a for-in loop to print out a "7 times table". Your output should look like this: 1 * 7 = 7 2 * 7 = 14
A: for number in 1...10 { println("(number) * 7 = (number*7)") }
Hope this helps. David
AR Ehsan
7,912 PointsI did that a long time ago. Thanks anyway