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 2.0 Basics Swift Types Recap: Swift Types

still stuck

I dont understand this

types.swift
// Enter your code below
let firstValue = 2
let secondValue = 4

let product = firstValue * secondValue

let output = " The product of \(firstValue) times \(secondValue) is eight"

6 Answers

Jennifer Nordell
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there! You were doing really well right up until the last line. And even there, it's just a couple of small things. You set up your product variable. Now we should use it in the string. Also, your string begins with a leading space which will cause the challenge to fail. Take a look at how close you are:

let output = "The product of \(firstValue) times \(secondValue) is \(product)"

This will set the output string to "The product of 2 and 4 is 8". You hardcoded in your "eight". We want it to be flexible and change depending on the numbers we put in. Hope this helps! :sparkles:

Michael Oliver
Michael Oliver
7,855 Points

Jennifer, your attitude is so encouraging, it helps newbies, thank you!!

Hi I have and nothing seems to have been done about it. Im on conditions and logical operators i understood everything and actually found it pretty simple however the challenege is extremly confusing and doesn't make sense. please help Jennifer Nordell

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.

If the number is indeed both an odd number and a multiple of 7, append the value to the results array provided.

Hint: To check for an odd number use the not operator to check for "not even

var results: [Int] = []

for n in 1...100 { // Enter your code below if n = odd && is! even {print ("results")}

// End code 

}

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there Alia! While I do sympathize with the inability to use the "Get Help" button at the present time, I also feel like this thread is starting to get a bit long. We now have two solutions to two separate challenges in one thread.

It's always best to start a new thread for a new problem, as this will allow other students the opportunity and learning experience of helping you troubleshoot. This way, you'll probably get answers faster, as I'm not always online, and posting your new questions like this will likely only be seen by me.

To post a brand new question, you can click on the "Community" link at the top of this page and then click the "Ask" button. It will ask you to fill in some information. To learn to correctly post your code, please see the "Markdown Cheatsheet" link at the bottom of the "Add an answer" section. :arrow_down:

Good luck! :sparkles:

thank you so much :)

i agree so kind and helpful :)

Apologies my help button is not working so Im having to use this. Jennifer Nordell

This is the task Im stuck on its LOOPs

We have a variable ,sum, that will store the value of the sum of numbers from the array.

We also have a variable ,counter, which we will use to track the number of iterations of the while loop.

Step 1: Create a while loop. The while loop should continue as long as the value of counter is less than the number of items in the array. (Hint: You can get that number by using the count property)

let numbers = [2,8,1,16,4,3,9] var sum = 0 var counter = 0

// Enter your code below

while counter < numbers.count {print (counter)} counter++ }

what have i done wrong

Jennifer Nordell
seal-mask
.a{fill-rule:evenodd;}techdegree
Jennifer Nordell
Treehouse Teacher

Hi there Alia Khan! Sorry for the delay in getting back to you. It's odd that your "Get help" button doesn't work. I might suggest reporting this to Treehouse support. However, given that you're stuck I'll help you out here in the comments instead.

But before I explain the code, let me give you some tips about Treehouse challenges in general. Read the instructions carefully and try not to do anything they don't explicitly ask for. For example, nowhere in the instructions does it say to print anything. But you're printing your counter. Even if this code is functional, it could cause the challenge to fail.

Now, here's the code and I'll walk you through it.

let numbers = [2,8,1,16,4,3,9]
var sum = 0
var counter = 0

// Enter your code below
while counter < numbers.count {
  sum += numbers[counter]
  counter++
}

Ok, so they give us an array named numbers. And they've already set it up for us. What they want us to do is go down that list and add up all the numbers in that array. This will result in 43. So we set up our while loop and that part you did just fine. You even incremented the counter correctly! But instead of your print we need to take the sum variable and add the number that's in that spot in the array. So when counter is 0 it will add the number at numbers[0]. That is 2. Now sum is equal to 2. In the next iteration, counter will be equal to 1. And numbers[1] is equal to 8. We add that to sum to bring us to a running total of 10. And we continue this way through the entire length of the array. When the loop exits, sum will hold a value of 43.

Hope this helps! :sparkles: