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

how can i create a constant named "title" and assigned to a string named "A dance with the dragon" ?

how can i create a constant named "title" and assigned to a string named "a dance with the dragon" ?

numbers.swift
let Title ("A dance with dragons")

2 Answers

itΒ΄s easier then it looks ;-)

let title = "A dance with the dragon"

first you set WHAT it is... "let" is a constant value, NOT changeable once itΒ΄s been defined. "var" is a variable and can be changed and modified as many times as you like.

so we start with a let since we want a constant. now title... in programming (any language) itΒ΄s best practice to use something called "camelCasing" (you can see it hu? :-))

means the name of a variable, constant, function,... STARTS with lowercase and then continues every word upper case..

Title of movie would be "titleOfMovie"

so

let title = "A dance with the dragon"

We want that the constant "title" EQUALS "A dance with the dragon" so we write it that way ;-)

Thank you. i just started so its kinda hard :)