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 trial

iOS Swift Basics (retired) Control Flow For-In Loop

Chris Kirec
Chris Kirec
430 Points

for-in loops

I'm having trouble with this questions and can't figure out where I am going wrong.

Use a for-in loop to print out a "7 times table". Your output should look like this: 1 * 7 = 7 2 * 7 = 14 Etc., all the way up to 10. Each line should be on a new line.

In my code when I try on xCode and replace the * with "times 7 is" it prints correctly but when I replace that with * it doesn't print. How do I ensure * is used as a symbol and not as an operation?

for_loops.swift
for number in 1...10 {
  println("\(number) * \(number*7)")
  }
Chris Kirec
Chris Kirec
430 Points

I get the following error

Bummer! You didn't println the right values. You printed [1 * 7, 2 * 14, 3 * 21, 4 * 28, 5 * 35, 6 * 42, 7 * 49, 8 * 56, 9 * 63, 10 * 70], but we were looking for [1 * 7 = 7, 2 * 7 = 14, 3 * 7 = 21, 4 * 7 = 28, 5 * 7 = 35, 6 * 7 = 42, 7 * 7 = 49, 8 * 7 = 56, 9 * 7 = 63, 10 * 7 = 70].

1 Answer

Gabe Nadel
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Gabe Nadel
Treehouse Guest Teacher

Well, it looks like you are missing the equals sign. You are printing "1 * 7"...but you should be printing "1 * 7 = 7"...you'll need to structure your string a it differently to get that, but you are pretty close.

Also, your second line is: "2 * 14" where it should be "2 * 7 = 14" ...look at the difference there, as it may be more evident than the looking at the first line. (They have the same solution, it's just more obvious with 2 * 7 = 14;

Chris Kirec
Chris Kirec
430 Points

thanks for the help...I got it to work with the following

for number in 1...10{
    println(" 7 X \(number) = \(number * 7)")