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

Joe Blow
PLUS
Joe Blow
Courses Plus Student 229 Points

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

Daniel Sattler
Daniel Sattler
4,867 Points

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 ;-)

Joe Blow
PLUS
Joe Blow
Courses Plus Student 229 Points

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