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) Types Numbers

vibhor RAMPAL
vibhor RAMPAL
2,365 Points

let price = "9.99" I am trying to run this but getting a compile error

let price = "9.99"

I am trying to run this but getting a compile er

numbers.swift
let title = ("A Dance with Dragons")

let price = "6.99"
Ryan Jin
Ryan Jin
15,337 Points

When you declare the constant "title", you don't need to write its value in a pair of parenthesis. Also, when you are writing doubles, you don't need to add the pair of quotation marks around it, since quotation marks are only for strings and characters, not for numbers. Well, if the question asks you to write the price as a string, the " let price = "6.99" " will work. But the declaration of the title constant can cause a crash. So I believe you just write it out like this:

let title = "A Dance with Dragons"
let price = 6.99 // If the question asks you to write it as a string, keep it as let price = "6.99"

1 Answer

Hi, when you declare a String variable, it needs to be quoted, but if the variable is a number (integer, float, double), you only type the number. Should look like this:

let title = "A Dance with Dragons"

let price = 6.99