Variables
Introduction to variables and basic data types.
StartKey Concepts
Review core concepts you need to learn to master this subject
Variables
Variables
var score = 0
A variable refers to a storage location in the computer’s memory that one can set aside to save, retrieve, and manipulate data.
- 1The “Hello, world!” program simply writes to the screen. It does not read anything, calculate anything, or allow for user input. That’s no fun! Real programs tend to produce results based on some …
- 2Suppose we are building a game, and we want to keep track of the player’s name, the player’s score that goes from 0 to 10, the player’s level, etc. We need some variables! Before we can use a var…
- 3Computers are incredible at doing calculations. Now that we have declared variables, let’s use them with arithmetic operators to calculate things! Here are some arithmetic operators: - + additi…
- 4Sometimes the value of our variables need to be adjusted. We know that we can update our variables using arithmetic operators like this: var age = 99 age = age + 1 print(age) // Prints 100 We a…
- 6Often times, we find ourselves needing to insert values into a string. In these cases, we can use string interpolation. In Swift, to insert a value into a string using string interpolation, we …
- 8Now that we’ve learned about the basics of variables and arithmetic operators, let’s write a program! The mad scientist Kelvin has mastered predicting the weather in his mountain-side meteorology …
What you'll create
Portfolio projects that showcase your new skills
Dog Years
Dogs have ages that don't quite work like ours. This can be a little ruff when you want to know how old your dog would be if he/she is a human. Don't fret — build a dog-age-converting program to translate your dog's age into human years!
Quadratic Formula
Write a Swift program that solves the quadratic equation.
Piggy Bank
You just returned from a trip to South America and you came back with three different kinds of currencies. Let's convert them to USD!
How you'll master it
Stress-test your knowledge with quizzes that help commit syntax to memory