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

mohamed hassan
mohamed hassan
2,079 Points

i cant solve the challenge i tried using the remainder operation but it is not going through i get error

swift_lint.swift:10:35: error: cannot assign to value: '&&' returns immutable value

For this challenge, we'd like to know in a range of values from 1 to 100, how many numbers are both odd, and a multiple of 7.

To start us off, I've written a for loop to iterate over the desired range of values and named the local constant n. Your job is to write an if statement inside the for loop to carry out the desired checks.

var results: [Int] = []

for n in 1...100 {

   if n % [ 2 ] != 0 && n % [ 7 ] = 0  {
   print ( results )
   }

}

1 Answer

Hi there,

There's a couple of issues here but you've got most of that spot on. Good work!

First, remove the square brackets from around the 2 and the 7. Next, where you're checking if n is a multiple of 7 using the % operator, you want to compare to zero using double equals, not single. Change that to ==.

Lastly, you want to append() into the results array inside your if statement, not print. Use dot notation to chain .append() onto results and pass in n as the argument.

I hope that helps.

Steve.