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!
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
abdirahman libanCourses Plus Student 2,163 Points
i could't solve it
i could't solve the last coding challange in swift types videos please i need help
Jens Hagfeldt16,548 Points
In the first part of the challenge you are challenged to: declaring two constants, firstValue and secondValue and to both of them assign some integer values. (The naming of the constants is very important!) Remember that constants are declared with the keyword let. So here you could type in something like the following:
let firstValue = 2 let secondValue = 4
In the second part of the challenge you are first challenged to: declare a constant named product and assign the result of multiplying firstValue and secondValue together. This would easily be done by typing:
let product = firstValue * secondValue
And last you are challenged to: by using string interpolation, create a string literal that describes the operation you just performed. You are also given a string representing how they would like the output to read: "The product of 2 times 4 is 8". Also they want you to assign that to a constant named output. (Wow, so much to think about in one go... And again, the naming of the constants is very important. So I recommend you to start with the last thing first and declare the constant output with an empty string like here below:
let output = ""
But to succeed with the challenge you must get the output to read: The product of 2 times 4 is 8 (but maybe with other numbers if you prefer that), and this using string interpolation. Remember that string interpolation is when you incorporate values of other constants or variables into the same string?! This is done by surrounding the values with a backslash and parentheses like this: *(someValue). So copy the text string they provided into your empty string *" "** then replace the 2 the 4 and the 8 with *( )* and inside those put the name of your constants like below. This should do the trick so you can safely hit the CheckWork button.
let output = "The product of \(firstValue) times \(secondValue) is \(product)"
I hope my explanation helped, happy coding!
Antonija Pek5,819 Points
Antonija Pek5,819 Points
First part says just to declare 2 constants. We declare constants with
Then you have to add one more constant with a name
productwhich simply multiplies first and second value. Also task says we should have a constant that describes what we do. It says we should use string interpolation. That means we use this syntax
\(someConstant)between our "..." and it will output whatever value of that constant is. Since in this task we use integers, the value will be some number. It can be a number or something else like a string.