iOS Swift Collections and Control Flow Control Flow With Conditional Statements Working With Logical Operators

how do you append something to the results and how would you have the statement figure out the multiples ?

I just need to know how do you "append" something to the results variable and also how would you have the code printed out to figure out the multiples of 6.

1 Answer

Jennifer Nordell
MOD
Jennifer Nordell
Treehouse Moderator

Hi there! The answer to your question, is ironically, in your question. You can use the append method on the array. You learned about this already, but it's been a while. Take a look around 7:19 in this video for an example on how it's used. In the challenge, the loop is going to go through a range of numbers. Each time through the loop that number will increase by one. You asked about the multiples of 6 but the challenge linked here asks about appending numbers that are both odd and a multiple of 7.

We can use the modulus operator here to determine if one number is evenly divisible by another number. It's also known (very appropriately) as the "remainder operator". It was covered in this video around 2:10. For example, if I wrote 7 % 2 I would get a result back of 1. Seven is divisible by two three times with a remainder of 1. This is an easy way to check if something is even or odd. Any number that is evenly divisible by 2 will have a remainder of 0 when dividing by 2. When dividing by 2, if it does not have a remainder of 0, then it is odd.

This means also that we can check if any number is evenly divisible by any other number. If the first number modulus the second number equals zero, then the number is evenly divisible (perfect multiple). For example: 15 % 3 would return a 0. Fifteen is evenly divisible by 3 and a perfect multiple of 3. Fifteen divided by three results in 5 with zero remaining.

Hope this helps! :sparkles:

Thank you so much! This was very very helpful!