Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
50cc1ee
Update Contents.swift
marihamWasfy Jun 10, 2020
0c8cd42
Update Contents.swift
marihamWasfy Jun 10, 2020
2a33872
Update Contents.swift
marihamWasfy Jun 10, 2020
efe2635
Update Contents.swift
marihamWasfy Jun 10, 2020
944da9d
Update Contents.swift
marihamWasfy Jun 10, 2020
121799e
Update Contents.swift
marihamWasfy Jun 10, 2020
e054c31
Update Contents.swift
marihamWasfy Jun 10, 2020
2fe160a
Update Contents.swift
marihamWasfy Jun 10, 2020
f04cb58
Update Contents.swift
marihamWasfy Jun 10, 2020
9b7dd5b
Update Contents.swift
marihamWasfy Jun 10, 2020
384d7db
Update Contents.swift
marihamWasfy Jun 10, 2020
8b858cf
Update Contents.swift
marihamWasfy Jun 10, 2020
329c645
Update Contents.swift
marihamWasfy Jun 10, 2020
33d9833
Update Contents.swift
marihamWasfy Jun 10, 2020
a81b348
Update Contents.swift
marihamWasfy Jun 10, 2020
a7f1149
Update Contents.swift
marihamWasfy Jun 10, 2020
03ff5c5
Update Contents.swift
marihamWasfy Jun 10, 2020
4f042e8
Update Contents.swift
marihamWasfy Jun 10, 2020
37b82a2
Update Contents.swift
marihamWasfy Jun 10, 2020
754606b
Update Contents.swift
marihamWasfy Jun 10, 2020
95c3f62
Update Contents.swift
marihamWasfy Jun 10, 2020
adf709b
Update Contents.swift
marihamWasfy Jun 10, 2020
5c76060
Update Contents.swift
marihamWasfy Jun 10, 2020
8196297
Update Contents.swift
marihamWasfy Jun 10, 2020
0beeed0
Update Contents.swift
marihamWasfy Jun 10, 2020
46adab1
Update Contents.swift
marihamWasfy Jun 10, 2020
123772a
Update Contents.swift
marihamWasfy Jun 10, 2020
b170b4e
Update Contents.swift
marihamWasfy Jun 10, 2020
3fe9655
Update Contents.swift
marihamWasfy Jun 10, 2020
0b42d5e
Update Contents.swift
marihamWasfy Jun 10, 2020
7eab2b5
Update Contents.swift
marihamWasfy Jun 10, 2020
52231a3
Update Contents.swift
marihamWasfy 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
@@ -1,22 +1,28 @@
/*:
## Exercise: Use Playgrounds

import Foundation
/*:
## Exercise - Use Playgrounds
The code below prints a few short statements about what you have learned in this lesson. Open the console area and view the code's output.
*/

print("I have learned the following:")
print("What features make Swift a modern and safe language")
print("How to use the Swift REPL in Terminal")
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 ("I love it when you call me senorita")

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

print ("I wish I could pretend I didn't need ya")
print ("But every touch is ooh la la la")
print ("It's true, la la la")
print ("Ooh, I should be running")
print ("Ooh, you keep me coming for ya")



//: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
@@ -1,6 +1,6 @@
import Foundation
/*:
## Exercise - Use Playgrounds

The code below prints a few short statements about what you have learned in this lesson. Open the console area and view the code's output.
*/
print("I have learned the following:")
Expand All @@ -11,20 +11,22 @@ 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 ("I love it when you call me senorita")

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

print ("I wish I could pretend I didn't need ya")
print ("But every touch is ooh la la la")
print ("It's true, la la la")
print ("Ooh, I should be running")
print ("Ooh, you keep me coming for ya")


/*:

_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._
*/
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
import Foundation
/*:
## 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 = 900
print(friends)

/*:
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 = 800 - deleted line

/*:
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("No, because constants value set only once and can't be changed")

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

var age = 25
print(age)

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

age = 26
print(age)
/*:

*/
Expand All @@ -32,19 +36,35 @@
/*:
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
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 booleanVar = true
print(booleanVar)
booleanVar = false
print(booleanVar)

/*:
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 value1 = 0
//var value2 = 0.0 - deleted line
var value2: Int
value2 = value1

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

var largeNumber = 1000000000
var numberFormatter = NumberFormatter()
numberFormatter.numberStyle = NumberFormatter.Style.decimal
var formattedNumber = numberFormatter.string(from: NSNumber(value:largeNumber))
print (formattedNumber)
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/*:
## 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 = 1000

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

// friends = 900 - deleted line

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

print("No, because contast values can’t be changed once it’s set.")

//: page 1 of 10 | [Next: App Exercise - Step Goal](@next)
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
/*:
## 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 = 0 - deleted line
var percentCompleted: Double

/*:
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,14 @@
## 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)
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@

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, because it's a variable its value could be changed anytime while constant its values can’t be changed once it’s set.")

//: [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,14 @@

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)
print("Good job! You're well on your way to your daily goal.")

//: [Previous](@previous) | page 4 of 10 | [Next: Exercise - Constant or Variable?](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
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 = 450
var numberOfComments = 400
let yearCreated = 2019
let monthCreated = "June"
let dayCreated = 24



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,16 @@
- Average heart rate: The user's average heart rate over the last 24 hours
*/


let name = "Mira"
print("I set Name to constant because it won't change")
var age = 25
print("I set Age to variable because it will change yearly")
var numberOfSetpsToday = 15000
print("I set Number of steps taken today to variable because it will change daily")
var numberOfGoalSteps = 20000
print("I set Goal number of steps to variable because it will change daily")
var averageHeartRate = 75
print("I set Average heart rate to variable because it will change daily")



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,29 @@

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 = 0.1
var seconfDecimal = 0.2

/*:
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 - deleted line
print("No, error: cannot assign value of type 'Bool' to type 'Double'")

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

var name = "Mira"
//firstDecimal = name - deleted line
print("No, error: cannot assign value of type 'String' to type 'Double")

/*:
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 number = 2
//firstDecimal = number - deleted line
print("No, error: cannot assign value of type 'Int' to type '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 @@ -5,11 +5,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 = false

/*:
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 goalSetseps = 20_000
var currentSetpCount = 15_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 @@ -3,21 +3,25 @@

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
//print(name) = deleted line

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

name = "Mira"
print(name)

/*:
Declare a variable called `distanceTraveled` and set it to 0. Do not give it an explicit type.
*/
// var distanceTraveled = 0 - deleted line
var distanceTraveled: Double


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

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