Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
9215f65
Update Contents.swift
minarelaasser Jun 10, 2020
78e6cda
Update Contents.swift
minarelaasser Jun 10, 2020
1e68995
Update Contents.swift
minarelaasser Jun 10, 2020
7fca41e
Update Contents.swift
minarelaasser Jun 10, 2020
1078fd1
Update Contents.swift
minarelaasser Jun 10, 2020
f7dcf23
Update Contents.swift
minarelaasser Jun 10, 2020
98ec16a
Update Contents.swift
minarelaasser Jun 10, 2020
9da9455
Update Contents.swift
minarelaasser Jun 10, 2020
9961caa
Update Contents.swift
minarelaasser Jun 10, 2020
0e98182
Update Contents.swift
minarelaasser Jun 10, 2020
8820a31
Update Contents.swift
minarelaasser Jun 10, 2020
df8b0fb
Update Contents.swift
minarelaasser Jun 10, 2020
03d34cd
Update Contents.swift
minarelaasser Jun 10, 2020
2ede7a0
Update Contents.swift
minarelaasser Jun 10, 2020
7d05e3f
Update Contents.swift
minarelaasser Jun 10, 2020
a43649c
Update Contents.swift
minarelaasser Jun 10, 2020
dc2e0e3
Update Contents.swift
minarelaasser Jun 10, 2020
211c735
Update Contents.swift
minarelaasser Jun 10, 2020
b2b2b07
Update Contents.swift
minarelaasser Jun 10, 2020
d4ad7f0
Update Contents.swift
minarelaasser Jun 10, 2020
01a4a16
Update Contents.swift
minarelaasser Jun 10, 2020
e90e7a0
Update Contents.swift
minarelaasser Jun 10, 2020
5d52c6f
Update Contents.swift
minarelaasser Jun 10, 2020
574fb22
Update Contents.swift
minarelaasser Jun 10, 2020
129a56e
Update Contents.swift
minarelaasser Jun 10, 2020
530457f
Update Contents.swift
minarelaasser Jun 10, 2020
625afdb
Update Contents.swift
minarelaasser Jun 10, 2020
6688a6c
Update Contents.swift
minarelaasser Jun 10, 2020
005862d
Update Contents.swift
minarelaasser 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,30 +1,20 @@
/*:
## 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.
## 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 = 700
print(friends)


/*:
Use multiple `print` functions to write out some of the lyrics to the song.
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 = 500

/*:
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, it won't compile because friends is a 'let' constant .. you cant changet that:)")

_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._
*/
//: page 1 of 10 | [Next: App Exercise - Step Goal](@next)
Original file line number Diff line number Diff line change
@@ -1,50 +1,16 @@
/*:
## Exercise - Constants
## App Exercise - Step Goal

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


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


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


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


/*:
Now pretend you just had a birthday, and update the `age` variable accordingly. Print `age` to the console.
>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 = 1000

/*:

*/


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


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


/*:
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.
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 ("You step goal for the day is:")
print (goalSteps)


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

//: [Previous](@previous) | page 2 of 10 | [Next: Exercise - Variables](@next)
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
/*:
## 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 = 700
print(friends)


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

/*:
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, it won't compile because friends is a 'let' constant .. you cant changet that:)")


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

/*:
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.
*/
var stepGoal = 10_000
var stepsTaken = 3467

percentCompleted = (100.0 * Double(stepsTaken)) / Double(stepGoal)
print((percentCompleted),"%")

/*:

_Copyright © 2018 Apple Inc._

/*:
_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,15 @@
## 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 = 1000

/*:
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 ("You 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
@@ -1,18 +1,18 @@
/*:
/*:
## 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 = schooling+1; 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("Variables are made to be changable as opposed to 'constant' declared using 'let' keyword: once declared contant cant be changed:) ")

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

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 @@ -10,7 +10,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 = 1000
var numberOfComments = 250
let yearCreated = 2020
let monthCreated = "June"
let dayCreated = 10



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



let userName = "Minar El-Aasser"
print("User name wont change")
var userAge = 34
print("age changes every 12 months")
var goalNumberOfSteps = 300
print("the goal should be adjustable as you practice more:)")
var averageHeartRate = 75
print("your heart rate may vary due to your health condition in the last 24 hours from one day to another")


/*:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,37 @@
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 = 9.5
var secondDecimal = 5.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.
*/

let trueOrFalse = true
//firstDecimal = trueOrFalse
print("This above commented command won't allow the code to compile because you 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 myString = "My String"
//firstDecimal = myString
print("This above commented command won't allow the code to compile because you 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 wholeNumber = 10
//firstDecimal = wholeNumber
print("This above commented command won't allow the code to compile because you 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,21 @@

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

let 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.
*/
//to make it more readable in the code
var numberOfStepsGoal = 1000_000
//to make it more readable in the display
import Foundation
let numberFormatter = NumberFormatter()
numberFormatter.numberStyle = .decimal
var numberOfStepsGoalFormatted = numberFormatter.string(from: NSNumber(value:numberOfStepsGoal))!
print(numberOfStepsGoalFormatted)



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

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)

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


name = "Minar"
print(name)
/*:
Declare a variable called `distanceTraveled` and set it to 0. Do not give it an explicit type.
*/

var distanceTraveled: 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

//: [Previous](@previous) | page 9 of 10 | [Next: App Exercise - Percent Completed](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,37 @@

You decide to build a shed and want to know beforehand the area of your yard that it will take up. Create two constants, `width` and `height`, with values of 10 and 20, respectively. Create an `area` constant that is the result of multiplying the two previous constants together, and print out the result.
*/

let width = 10
let height = 20
let area = width * height
print(area)

/*:
You decide that you'll divide your shed into two rooms. You want to know if dividing it equally will leave enough room for some of your larger storage items. Create a `roomArea` constant that is the result of dividing `area` in half. Print out the result.
*/
let roomArea = area / 2; print(roomArea)


/*:
Create a `perimeter` constant whose value equals `width` plus `width` plus `height` plus `height`, then print out the result.
*/
let perimeter = width + width + height + height; print(perimeter)


/*:
Print what you would expect the result of integer division of 10 divided by 3 to be. Create a constant, `integerDivisionResult` that is the result of 10 divided by 3, and print the value.
*/

let integerDivisionResult = 10 / 3
print(integerDivisionResult)

/*:
Now create two constants, `double10` and `double3`, set to 10 and 3, and declare their types as `Double` values. Declare a final constant `divisionResult` equal to the result of `double10` divided by `double3`. Print the value of `divisionResult`. How does this differ from the value when using integer division?
*/
let double10:Double = 10
let double3:Double = 3
let divisionResult = double10 / double3
print(divisionResult)



/*:
Expand All @@ -33,6 +44,11 @@
*circumference = 2 * pi * radius.*
*/
let pi = 3.1415927
let radius = 5.0
let diameter = 2 * radius
let circumference = 2 * pi * radius
print("diameter: ", diameter)
print("circumference: ", circumference)


//: page 1 of 8 | [Next: App Exercise - Fitness Calculations](@next)
Loading