Exercise 1
Exercise 1
/*:
Now assume you go through and remove friends that aren't active on
social media. Attempt to update your `friends` constant to a lower
number than it currently is. Observe what happens and then move to the
next step.
*/
/*:
Does the above code compile? Why not? Print your explanation to the
console using the `print` function. Go back and delete your line of
code
that updates the `friends` constant to a lower number so that the
playground will compile properly.
*/
/*:
## Exercise 3 - Variables
Declare a variable `schooling` and set it to the number of years of
school that you have completed. Print `schooling` to the console.
*/
/*:
Now imagine you just completed an additional year of school, and
update
the `schooling` variable accordingly. Print `schooling` to the
console.
*/
/*:
Does the above code compile? Why is this different than trying to
update a constant? Print your explanation to the console using the
`print` function.
*/
/*:
## Exercise 4 - Types and Type Safety
Declare two variables, one called `firstDecimal` and one called
`secondDecimal`. Both should have decimal values. Look at both of
their types by holding Option and clicking on the variable name.
*/
/*:
Declare a variable called `trueOrFalse` and give it a boolean value.
Try to assign it to `firstDecimal` like so: `firstDecimal =
trueOrFalse`. Does it compile? Print a statement to the console
explaining why not, and remove the line of code that will not compile.
*/
/*:
Declare a variable and give it a string value. Then try to assign it
to
`firstDecimal`. Does it compile? Print a statement to the console
explaining why not, and remove the line of code that will not compile.
*/
/*:
Finally, declare a variable with a whole number value. Then try to
assign it to `firstDecimal`. Why won't this compile even though both
variables are numbers? Print a statement to the console explaining why
not, and remove the line of code that will not compile.
*/
/*:
## Exercise 5 - Type Inference and Required Values
Declare a variable called `name` of type `String`, but do not give it
a
value. Print `name` to the console. Does the code compile? Remove any
code that will not compile.
*/
/*:
Now assign a value to `name`, and print it to the console.
*/
/*:
Declare a variable called `distanceTraveled` and set it to 0. Do not
give it an explicit type.
*/
/*:
Now assign a value of 54.3 to `distanceTraveled`. Does the code
compile? Go back and set an explicit type on `distanceTraveled` so the
code will compile.
*/