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 trialNoah Muhammad
Courses Plus Student 641 Pointsbool
need help with boolean
// Enter your code below
let title = "A Dance with Dragons"
var rating = 7.5
let isAvailable = bool : false
2 Answers
Michael Afanasiev
Courses Plus Student 15,596 PointsHi Noah,
Your code is nearly perfect! Swift is an awesome language and you don't need to declare your variable type, it will automatically detect it for you. (Unless you want to be explicit, which you will learn about in the next set of videos)
Notice how you didn't declare a type of String
or a type of Double
, the same follows for the boolean value.
For example:
var thisIsAnAwesomeBool = true
Hint: Also, notice what the challenge is asking you to declare, a constant or a variable.
Hope this helps!?
Anthony Lafont
17,075 PointsHi Noah!
There are two aspects in any Swift expression: The value, expressed by the sign "=" that store a value in the computer memory. These data can be numbers (1, 4.5, 42) series of characters ("My name is Noah"), or binary response (true or false), etc.
The type, expressed by the sign ":" that indicate what kind of data will be stored in the property. Often, the compiler can infer witch kind of data is stored. You can use "Int" for an integer, "String" for a characters and "Bool" for a binary response, also called a Boolean value.
In your example, you indicate with the "=" symbol that the data stored is Bool. You gave a type, where the compiler wanted a value and vice versa. So, to pass the challenge, you just have to reverse the ":" with the "=", like this:
// Enter your code below
let title = "A Dance with Dragons"
var rating = 7.5
let isAvailable : Bool = false
As I told you, you don't even have to write the style, the compiler will automatically guess which type it is
// Enter your code below
let title = "A Dance with Dragons"
var rating = 7.5
let isAvailable = false
Hope this helps,
Anthony