Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e070ec3
Update Contents.swift
MaggieShammaa Jun 10, 2020
9efad87
Update Contents.swift
MaggieShammaa Jun 10, 2020
2cd0e91
Update Contents.swift
MaggieShammaa Jun 10, 2020
ecdd5a3
Update Contents.swift
MaggieShammaa Jun 10, 2020
aa15580
Update Contents.swift
MaggieShammaa Jun 10, 2020
f3c1c45
Update Contents.swift
MaggieShammaa Jun 10, 2020
637bb3c
Update Contents.swift
MaggieShammaa Jun 10, 2020
765f281
Update Contents.swift
MaggieShammaa Jun 10, 2020
e50ffc1
Update Contents.swift
MaggieShammaa Jun 10, 2020
d9909cf
Update Contents.swift
MaggieShammaa Jun 10, 2020
b8ca91b
Update Contents.swift
MaggieShammaa Jun 10, 2020
65f3b77
Update Contents.swift
MaggieShammaa Jun 10, 2020
ed3539c
Update Contents.swift
MaggieShammaa Jun 10, 2020
13f66be
Update Contents.swift
MaggieShammaa Jun 10, 2020
5bfad5f
Update Contents.swift
MaggieShammaa Jun 10, 2020
cf39ddf
Update Contents.swift
MaggieShammaa Jun 10, 2020
87e35f6
Update Contents.swift
MaggieShammaa Jun 10, 2020
7da51d7
Update Contents.swift
MaggieShammaa Jun 10, 2020
99ab6ae
Update Contents.swift
MaggieShammaa Jun 10, 2020
c646c22
Update Contents.swift
MaggieShammaa Jun 10, 2020
0d5ecfd
Update Contents.swift
MaggieShammaa Jun 10, 2020
bf5b64f
Update Contents.swift
MaggieShammaa Jun 10, 2020
83a8728
Update Contents.swift
MaggieShammaa Jun 10, 2020
b035c76
Update Contents.swift
MaggieShammaa Jun 10, 2020
0b485c6
Update Contents.swift
MaggieShammaa Jun 10, 2020
25ee444
Update Contents.swift
MaggieShammaa Jun 10, 2020
7145d43
Update Contents.swift
MaggieShammaa Jun 10, 2020
1eaa776
Update Contents.swift
MaggieShammaa Jun 10, 2020
b290562
Update Contents.swift
MaggieShammaa Jun 10, 2020
72b5688
Update Contents.swift
MaggieShammaa Jun 10, 2020
8a7ec8e
Update Contents.swift
MaggieShammaa Jun 10, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ print("How to use playgrounds to make writing Swift fun and simple")
/*:
Now print your own phrases to the console. Pick one of your favorite songs. Use your knowledge of the `print` function to display the song title and artist.
*/

print("Shape of my heart")
print("Sting")

/*:
Use multiple `print` functions to write out some of the lyrics to the song.
*/
print("I know that the spades are the swords of a solider")
print("I know that clubs are weapons of war")
print("I know that diamonds mean money for this art")
print("But that's not the shape of my heart")


//:page 14 of 16 | [Next: Exercise: Go! Fight! Win!](@next)
//:page 14 of 16 | [Next: Exercise: Go! Fight! Win!](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,17 @@ print("How to use playgrounds to make writing Swift fun and simple")
/*:
Now print your own phrases to the console. Pick one of your favorite songs. Use your knowledge of the `print` function to display the song title and artist.
*/

print("Shape of my heart")
print("Sting")

/*:
Use multiple `print` functions to write out some of the lyrics to the song.
*/


print("I know that the spades are the swords of a solider")
print("I know that clubs are weapons of war")
print("I know that diamonds mean money for this art")
print("But that's not the shape of my heart")

/*:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,31 @@

Declare a constant called `friends` to represent the number of friends you have on social media. Give it a value between 50 and 1000. Print out the value by referencing your constant.
*/

let friends=755

/*:
Now assume you go through and remove a lot of your friends that aren't active on social media. Update your `friends` constant to a lower number than it currently is between 1 and 900.
*/

//friends=700


/*:
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 `friend` constant to a lower number so that the playground will compile properly.
*/

print("constants are fixed values")

/*:
Declare a variable `age` and set it to your own age. Print `age` to the console.
*/

var age=27
print(age)

/*:
Now pretend you just had a birthday, and update the `age` variable accordingly. Print `age` to the console.
*/
age=28
print(age)

/*:

Expand All @@ -32,19 +37,37 @@
/*:
Create a double variable with a value of 1.1. Update it to 2.2, 3.3, and 4.4. Print out the value after each assignment (again by referencing the variable you created).
*/
var value=1.1
print(value)
value=2.2
print(value)
value=3.3
print(value)
value=4.4
//print(value)


/*:
Create a Boolean variable and set it to `true`. Print the variable, then assign it a value of `false`, and print it again.
*/

var trueORFalse=true
print(trueORFalse)
trueORFalse=false
print(trueORFalse)

/*:
Create two variables: one with a value of 0, the other with a value of 0.0. Try to assign the second variable to the first, and you'll receive an error. Add the necessary type annotation to allow the second variable to be assigned to the first.
*/

var decimalValue: Float
decimalValue=0
print(decimalValue)
decimalValue=0.0
print(decimalValue)

/*:
Create a variable integer with a value of 1,000,000,000. Format it using commas, so it's easier to read.
*/

var integerValue:Int
integerValue=1_000_000_000


Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*:
## Exercise - Constants

Declare a constant called `friends` to represent the number of friends you have on social media. Give it a value between 50 and 1000. Print out the value by referencing your constant.
*/


*/let friends=755
print(friends)
//friends=700
//print(friends)
print("The code cannot compile because a constant cannot be updated")
/*:
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.
*/
Expand All @@ -15,4 +16,4 @@
*/


//: page 1 of 10 | [Next: App Exercise - Step Goal](@next)
//: page 1 of 10 | [Next: App Exercise - Step Goal](@next)"
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
/*:
## App Exercise - Percent Completed

>These exercises reinforce Swift concepts in the context of a fitness tracking app.

You decide that your fitness tracking app should show the user what percentage of his/her goal has been achieved so far today. Declare a variable called `percentCompleted` and set it to 0. Do not explicity assign it a type.
*/

var percentCompleted: Float

/*:
Imagine that partway through the day a user has taken 3,467 steps out of the 10,000 step goal. This means he/she is 34.67% of the way to his/her goal. Assign 34.67 to `percentCompleted`. Does the code compile? Go back and explicity assign a type to `percentCompleted` that will allow the code to compile.
*/

percentCompleted=34.67

/*:

_Copyright © 2018 Apple Inc._

_Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:_

_The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software._

_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE._
*/
//: [Previous](@previous) | page 10 of 10
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
## App Exercise - Step Goal

>These exercises reinforce Swift concepts in the context of a fitness tracking app.

Your fitness tracking app needs to know goal number of steps per day. Create a constant `goalSteps` and set it to 10000.
*/
*/let goalSteps=10000


/*:
Use two `print` functions to print two separate lines to the console. The first line should say "Your step goal for the day is:", and the second line should print the value of `goalSteps` by referencing your constant.
*/

print("Your step goal for the day is:")
print(goalSteps)

//: [Previous](@previous) | page 2 of 10 | [Next: Exercise - Variables](@next)


//: page 1 of 10 | [Next: App Exercise - Step Goal](@next)"
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@
## Exercise - Variables

Declare a variable `schooling` and set it to the number of years of school that you have completed. Print `schooling` to the console.
*/
*/var schooling=12
print(schooling)


/*:
Now imagine you just completed an additional year of school, and update the `schooling` variable accordingly. Print `schooling` to the console.
*/

schooling=13
print(schooling)

/*:
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.
*/
*/print("Yes as this is a variable and its flexible to change its value")


//: [Previous](@previous) | page 3 of 10 | [Next: App Exercise - Step Count](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

Create a variable called `steps` that will keep track of the number of steps you take throughout the day. Set its initial value to 0 to represent the step count first thing in the morning. Print `steps` to the console.
*/

var steps=0
print(steps)

/*:
Now assume the tracker has been keeping track of steps all morning, and you want to show the user the latest step count. Update `steps` to be 2000. Print `steps` to the console. Then print "Good job! You're well on your way to your daily goal."
*/

steps=2000
print(steps)

//: [Previous](@previous) | page 4 of 10 | [Next: Exercise - Constant or Variable?](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

For each of the metrics above, declare either a constant or a variable and assign it a value corresponding to a hypothetical post. Be sure to use proper naming conventions.
*/




var numberofLikes=20
var numberofComments=8
let yearCreated=2019
let monthCreated=5
let dayCreated=25

//: [Previous](@previous) | page 5 of 10 | [Next: App Exercise - Fitness Tracker: Constant or Variable?](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
- Goal number of steps: The user's goal for number of steps to take each day
- Average heart rate: The user's average heart rate over the last 24 hours
*/





let name="Maggie"
print("The name of the user is fixed")
let age=27
print("The age of the person is fixed")
var steps=2000
print("The number of steps increases along the day")
let goal=10000
print("The goal number of steps is fixed")
var heartRate=70
print("The average heart rate changes with time")
/*:
Now go back and add a line after each constant or variable declaration. On those lines, print a statement explaining why you chose to declare the piece of information as a constant or variable.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,25 @@

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.
*/

var firstDecimal=2.15
var secondDecimal=3.16

/*:
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.
*/


var trueOrFalse=true
//firstDecimal=trueOrFalse
/*:
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.
*/

print("It will not compile because it is type-safe")

/*:
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.
*/

var wholeNum = 5
//firstDecimal = wholeNum
print("It will not compile because one is integer and the other is double")

//: [Previous](@previous) | page 7 of 10 | [Next: App Exercise - Tracking Different Types](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
You have declared a number of constants and variables to keep track of fitness information. Declare one more variable with a boolean value called `hasMetStepGoal`.
*/


var hasMetStepGoal : Bool
hasMetStepGoal = true
/*:
When you declared a constant for goal number of steps and a variable for current step count, you likely assigned each a value in the thousands. This can be difficult to read. Redeclare this constant and variable and, when assigning each a value in the thousands, format the number so that it is more readable.
*/
let goalSteps = 10_000
var cuurentStepsCount=2_000


//: [Previous](@previous) | page 8 of 10 | [Next: Exercise - Type Inference and Required Values](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@
## Exercise - 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.
*/
*/var name: String



/*:
Now assign a value to `name`, and print it to the console.
*/

name="Maggie"
print(name)

/*:
Declare a variable called `distanceTraveled` and set it to 0. Do not give it an explicit type.
*/

var distanceTravele: Float

/*:
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.
*/

distanceTraveled = 54.3
print(distanceTraveled)

//: [Previous](@previous) | page 9 of 10 | [Next: App Exercise - Percent Completed](@next)
Loading