From 792cfee9e6f8bfae392ae2ef33310a8b6742a05a Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 16:44:23 +0200 Subject: [PATCH 01/21] Update Contents.swift --- .../Contents.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift index cd86d9d..429b7d9 100644 --- a/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift @@ -10,13 +10,14 @@ 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("lullaby") /*: Use multiple `print` functions to write out some of the lyrics to the song. */ - +print("The sky is amazing") +print("just like your eye") /*: From a15a51288af6175dd10a02c06b508cc29a94885b Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:12:40 +0200 Subject: [PATCH 02/21] Update Contents.swift --- .../1. Exercise - Constants.xcplaygroundpage/Contents.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift index 8721318..03f755b 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift @@ -4,15 +4,18 @@ 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. */ +var friends = 500 + /*: 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 = 220 /*: 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("let makes variable unchangable, so we need to make it var\(friends) ") //: page 1 of 10 | [Next: App Exercise - Step Goal](@next) From a7243d95166148cb03d45ed1f228381e67e5ca33 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:14:28 +0200 Subject: [PATCH 03/21] Update Contents.swift --- .../Contents.swift | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift index b71a821..4ab40a3 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift @@ -5,11 +5,14 @@ Your fitness tracking app needs to know goal number of steps per day. Create a constant `goalSteps` and set it to 10000. */ +let goalsteps = 3000 // now this is a constant not a variable + /*: 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) From 96bc9dc59bde0f3b82b343ddf30b4d24604fe702 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:16:21 +0200 Subject: [PATCH 04/21] Update Contents.swift --- .../3. Exercise - Variables.xcplaygroundpage/Contents.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift index 1b6fe9b..b1f0724 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift @@ -3,16 +3,20 @@ 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 = 9 +print(schooling) /*: Now imagine you just completed an additional year of school, and update the `schooling` variable accordingly. Print `schooling` to the console. */ +schooling = 10 +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("because var is a variable we can update the value several times") //: [Previous](@previous) | page 3 of 10 | [Next: App Exercise - Step Count](@next) From acb7c1d95387f3358367433d895afcdd0f9af9dd Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:18:20 +0200 Subject: [PATCH 05/21] Update Contents.swift --- .../Contents.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift index 4c95fb5..91bf420 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift @@ -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("Good Morning your start setp number is : \(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 ( "Good job! You're well on your way to your daily goal.") //: [Previous](@previous) | page 4 of 10 | [Next: Exercise - Constant or Variable?](@next) From d1375f400482641a479d8030058fe962257869c1 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:19:40 +0200 Subject: [PATCH 06/21] Update Contents.swift --- .../Contents.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift index 1d38a49..7586d7d 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift @@ -12,6 +12,22 @@ */ +var likes = 0 +var comments = 0 +let year = 2020 +let month : String +month = "june" +let day = 1 + + + +/* Name: The user's name + - Age: The user's age + - Number of steps taken today: The number of steps that a user has taken today + - 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 */ + + From ae6f21173c02c4412be8840bef4a0dde008d5c76 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Thu, 18 Jun 2020 17:21:47 +0200 Subject: [PATCH 07/21] Update Contents.swift --- .../Contents.swift | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift index a9bfc4b..85dd099 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift @@ -12,6 +12,16 @@ - Average heart rate: The user's average heart rate over the last 24 hours */ +let name : String +print ("A person name wont change") +let age = 0 +print("A person age wont change") +var steps2 = 0 +print("number of steps taken need to be updated along the day") +let goal2 = 0 +print("A person goal wont change") +var heartrate = 0 +print("heartrate will change according to activity") From c2bb0c466ab98e1b1cd358bca0d4473e6f68c83b Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 06:22:39 +0200 Subject: [PATCH 08/21] Update Contents.swift --- .../Contents.swift | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift index 6a26c32..e7563aa 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift @@ -3,21 +3,28 @@ 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.0 +var secondDecimal = 0.1 /*: 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 +print("cant assign boolean to 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 trueOrFalse2 = "true" +//firstDecimal = trueOrFalse2 +print("cant assign string to 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 trueOrFalse3 = 3 +//firstDecimal = trueOrFalse3 +print("cant assign int to double") //: [Previous](@previous) | page 7 of 10 | [Next: App Exercise - Tracking Different Types](@next) From 803636bf05ef61877c566ac6dca5acc1bfb00fc2 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 06:27:34 +0200 Subject: [PATCH 09/21] Update Contents.swift --- .../Contents.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift index 1badf6b..0d09bed 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift @@ -6,10 +6,11 @@ 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 = 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 goalnumber = 20_000 +var currentstepcount = 80_000 //: [Previous](@previous) | page 8 of 10 | [Next: Exercise - Type Inference and Required Values](@next) From cfb6db6099dca528b8d1f1d94c3627012cbae5fc Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 06:45:50 +0200 Subject: [PATCH 10/21] Update Contents.swift --- .../Contents.swift | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift index 5c81e84..49c82a5 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift @@ -3,21 +3,23 @@ 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 = "yassmina" +print(name) /*: Declare a variable called `distanceTraveled` and set it to 0. Do not give it an explicit type. */ - +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) From 9921bad302c46f3b8bb35bfbdafe40e1a7ff47c3 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 06:49:20 +0200 Subject: [PATCH 11/21] Update Contents.swift --- .../Contents.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift index 21166b7..01b73da 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift @@ -5,12 +5,12 @@ 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 /*: 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 /*: From 4c5a0e5ee3a4af457e7e67eebbb7772f4860f031 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 09:21:01 +0200 Subject: [PATCH 12/21] Update Contents.swift --- .../Contents.swift | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift index 4cbbad4..ec29949 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift @@ -23,7 +23,12 @@ /*: 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 +let double3 : Double +double10 = 10 +double3 = 3 +let divisionResult = double10 / double3 +print(divisionResult) /*: Given the value pi (3.1415927), create a `radius` constant with a value of 5.0, then calculate the diameter and circumference of the circle using the following equations, and print the results: @@ -34,5 +39,9 @@ */ let pi = 3.1415927 +let radius = 5.0 + +let diameter = 2 * radius +let circumference = 2 * pi * radius //: page 1 of 8 | [Next: App Exercise - Fitness Calculations](@next) From 13057dd7580b13e74e1b5377fc2d2d5009407b9a Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 09:37:23 +0200 Subject: [PATCH 13/21] Update Contents.swift --- .../Contents.swift | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift index 7384367..72a3840 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift @@ -5,16 +5,36 @@ Your fitness tracker keeps track of users' heart rate, but you might also want to display their average heart rate over the last hour. Create three constants, `heartRate1`, `heartRate2`, and `heartRate3`. Give each constant a different value between 60 and 100. Create a constant `addedHR` equal to the sum of all three heart rates. Now create a constant called `averageHR` that equals `addedHR` divided by 3 to get the average. Print the result. */ - +let heartRate1 = 60 +let heartRate2 = 80 +let heartRate3 = 100 +let addedHR = heartRate1 + heartRate2 + heartRate3 +let averageHR = addedHR / 3 +print(averageHR) /*: Now create three more constants, `heartRate1D`, `heartRate2D`, and `heartRate3D`, equal to the same values as `heartRate1`, `heartRate2`, and `heartRate3`. These new constants should be of type `Double`. Create a constant `addedHRD` equal to the sum of all three heart rates. Create a constant called `averageHRD` that equals the `addedHRD` divided by 3 to get the average of your new heart rate constants. Print the result. Does this differ from your previous average? Why or why not? */ +let heartRate1D : Double +let heartRate2D : Double +let heartRate3D : Double +heartRate1D = 60 +heartRate2D = 80 + heartRate3D = 100 +let addedHRD = heartRate1D + heartRate2D + heartRate3D +let averageHRD = addedHRD / 3 +print(averageHRD) +print("yes because they are all double values") /*: Imagine that partway through the day a user has taken 3,467 steps out of the 10,000 step goal. Create constants `steps` and `goal`. Both will need to be of type `Double` so that you can perform accurate calculations. `steps` should be assigned the value 3,467, and `goal` should be assigned 10,000. Create a constant `percentOfGoal` that equals an expression that evaluates to the percent of the goal that has been achieved so far. */ - +let steps : Double +let goal : Double +steps = 3_467 +goal = 10_000 +let percentOfGoal = (steps/goal)*100 +print(percentOfGoal) //: [Previous](@previous) | page 2 of 8 | [Next: Exercise - Compound Assignment](@next) From f9b800c1e3c515fab2d27e0b4760d7cfed7c837d Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 12:54:31 +0200 Subject: [PATCH 14/21] Update Contents.swift --- .../Contents.swift | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift index b0c97b5..6438485 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift @@ -4,7 +4,11 @@ Declare a variable whose value begins at 10. Using addition, update the value to 15 using the compound assignment operator. Using multiplication, update the value to 30 using compound assignment. Print out the variable's value after each assignment. */ - +var value = 10 +value = value + 5 +print(value) +value *= 5 +print(value) // compound operator /*: Create a variable called `piggyBank` that begins at 0. You will use this to keep track of money you earn and spend. For each point below, use the right compound assignment operator to update the balance in your piggy bank. @@ -18,6 +22,17 @@ */ +var piggybank = 0 +piggybank += 10 +print(piggybank) +piggybank += 20 +print(piggybank) +piggybank /= 2 +print(piggybank) +piggybank *= 3 +print(piggybank) +piggybank -= 3 +print(piggybank) From c10679c9d8254d96ba233c24f0aa9be467f72484 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 13:05:30 +0200 Subject: [PATCH 15/21] Update Contents.swift --- .../Contents.swift | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift index 881654a..15c2587 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift @@ -5,13 +5,19 @@ The most basic feature of your fitness tracking app is counting steps. Create a variable `steps` and set it equal to 0. Then increment its value by 1 to simulate a user taking a step. */ +var steps = 0 +steps += 1 /*: In addition to tracking steps, your fitness tracking app tracks distance traveled. Create a variable `distance` of type `Double` and set it equal to 50. This will represent the user having traveled 50 feet. - You decide, however, to display the distance in meters. 1 meter is approximately equal to 3 feet. Use a compound assignment operator to convert `distance` to meters. Print the result. */ +var distance : Double +distance = 50 + distance *= 3 +print(distance) + //: [Previous](@previous) | page 4 of 8 | [Next: Exercise - Order of Operations](@next) From 8b6e6aa0bb6ae63f8dd6b6e28cfc718bf898c8d6 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 13:11:55 +0200 Subject: [PATCH 16/21] Update Contents.swift --- .../Contents.swift | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift index e8378a0..343b81c 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift @@ -4,20 +4,23 @@ Print out what you think 10 + 2 * 5 evaluates to. Then print out the actual expression (i.e. `print(10 + 2 * 5)`) */ - +var myanswer = 20 +var trueanswer = 10 + 2 * 5 +print(trueanswer) /*: In a separate `print` statement, add in the necessary parentheses so that addition takes place before multiplication. */ - +print(((10 + 2) * 5)) /*: Print out what you think 4 * 9 - 6 / 2 evaluates to. Then print out the actual expression. */ - +print(33) +print(4 * 9 - 6 / 2 ) /*: In a separate `print` statement, add in the necessary parentheses so that the subtraction is prioritized over the multiplication and division. */ - +print(4 * (9 - 6) / 2 )// - * / //: [Previous](@previous) | page 5 of 8 | [Next: App Exercise - Complex Fitness Calculations](@next) From 40846a467902903b06ba7ca1631b6bb3c584f877 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 13:30:01 +0200 Subject: [PATCH 17/21] Update Contents.swift --- .../Contents.swift | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift index 1f2189c..822c70e 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift @@ -1,3 +1,4 @@ + /*: ## App Exercise - Complex Fitness Calculations @@ -5,6 +6,16 @@ If you completed the Fitness Calculations exercise, you calculated an average heart rate to display to the user. However, using proper order of operations you can do this in fewer steps. Create three separate heart rate constants, all of type `Double`, with values between 60 and 100. Then create a constant equal to the average heart rate. If you use correct order of operations you can do the heart calculation in one line. */ +var heartRate1 : Double +var heartRate2 : Double +var heartRate3 : Double + +heartRate1 = 60 +heartRate2 = 80 +heartRate3 = 100 + +let avg = (heartRate1+heartRate2+heartRate1) / 3 +print(avg) /*: @@ -12,6 +23,7 @@ You may want to also show the temperature in celsius. You can convert fahrenheit to celsius by taking `tempInFahrenheit` and subtracting 32, then multiplying the result by (5.0/9.0). Create a constant `tempInCelsius` that calculates in one line the temperature in celsius. */ +let tempInFahrenheit = 98.6 +let tempinCelsius = (tempInFahrenheit - 32 ) * (5/9) +print(tempinCelsius) - -//: [Previous](@previous) | page 6 of 8 | [Next: Exercise - Numeric Type Conversion](@next) From 18b24e7ad159d50f4e1d34be41e7fe526b55e804 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 13:42:10 +0200 Subject: [PATCH 18/21] Update Contents.swift --- .../Contents.swift | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift index 93698b8..4981688 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift @@ -1,18 +1,22 @@ /*: ## Exercise - Numeric Type Conversion - Create an integer constant `x` with a value of 10, and a double constant `y` with a value of 3.2. Create a constant `multipliedAsIntegers` equal to `x` times `y`. Does this compile? If not, fix it by converting your `Double` to an `Int` in the mathematical expression. Print the result. */ - +let x : Int +x = 10 +let y : Double +y = 3.2 +let multipliedAsIntegers = x * Int(y) +print (multipliedAsIntegers) /*: Create a constant `multipliedAsDoubles` equal to `x` times `y`, but this time convert the `Int` to a `Double` in the expression. Print the result. */ - - +let multipliedAsDoubles = Double(x)*y +print(multipliedAsDoubles) /*: Are the values of `multipliedAsIntegers` and `multipliedAsDoubles` different? Print a statement to the console explaining why. */ - +print("yes, because in first converting to Int truncate 0.2") //: [Previous](@previous) | page 7 of 8 | [Next: App Exercise - Converting Types](@next) From cb2abb8e227ca9448f49784da4e37c2028d55c2e Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 13:48:01 +0200 Subject: [PATCH 19/21] Update Contents.swift --- .../Contents.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift index 5de2f53..efc2abb 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift @@ -8,6 +8,17 @@ Now create a constant `percentOfGoal` of type `Double` that equals the percent of the goal that has been reached so far. You'll need to convert your constants of type `Int` to be of type `Double` in your calculation. */ +let steps : Int +steps = 2000 +let goal : Int +goal = 10_000 + +let percentOfGoal : Double + + +percentOfGoal = Double(steps)/Double(goal)*100 +print(percentOfGoal) + /*: From 8f3ceed93a5d245797655ea3eb774fee973e8367 Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 14:51:33 +0200 Subject: [PATCH 20/21] Update Contents.swift --- .../Contents.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift index 5db9740..3b355b1 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift @@ -9,10 +9,21 @@ Another friend brings up a restaurant she thinks will fit both of your criteria. This restaurant's attributes are represented by a few constants below. Write an if-else statement that will print "Let's go!" if the restaurant's attributes match the group's dietary requirements, and otherwise will print "Sorry, we'll have to think of somewhere else." */ -let hasFish = true -let hasPizza = false -let hasVegan = true +let hasFish : Bool +let hasPizza : Bool +let hasVegan : Bool +hasFish = true +hasPizza = true +hasVegan = true + +if ((hasVegan == true ) && ( (hasPizza || hasFish) == true ) ) +{ +print("continue ") } +else +{ +print("we need somehwere else") +} /*: Imagine you're trying to decide whether or not to go on a walk. You decide that you'll go on a walk if it's not raining or if it's 82 degress or warmer and sunny out. Create a constant `isNiceWeather` that is equal to an expression that evaluates to a boolean indicating whether or not the weather is nice enough for you to go for a walk. Write an if statement that will print "I'm going for a walk!" if the weather is nice. From 3f0d29a6fd1c99a40197bd606b12975e5ba186fd Mon Sep 17 00:00:00 2001 From: YasminAMassoud <55138409+YasminAMassoud@users.noreply.github.com> Date: Fri, 19 Jun 2020 14:54:34 +0200 Subject: [PATCH 21/21] Update Contents.swift --- .../Contents.swift | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift index d0d23b3..a03b97f 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift @@ -1,15 +1,27 @@ -/*: - ## App Exercise - Fitness Decisions - - >These exercises reinforce Swift concepts in the context of a fitness tracking app. - +@@ -6,10 +6,25 @@ You want your fitness tracking app to give as much encouragement as possible to your users. Create a variable `steps` equal to the number of steps you guess you've taken today. Create a constant `stepGoal` equal to 10,000. Write an if-else statement that will print "You're almost halfway there!" if `steps` is less than half of `stepGoal`, and will print "You're over halfway there!" if `steps` is greater than half of `stepGoal`. */ +var steps = 1000 +let stepGoal = 10_000 +if steps < (stepGoal/2) +{ +print("you are halfway") + +} else { + +print ("you are halfway there") +} /*: Now create a new, but similar, if-else-if statement that prints "Way to get a good start today!" if `steps` is less than a tenth of `stepGoal`, prints "You're almost halfway there!" if `steps` is less than half of `stepGoal`, and prints "You're over halfway there!" if `steps` is greater than half of `stepGoal`. */ +if steps < stepGoal/10 { +print("good start ") } +else if +steps < stepGoal/2 { +print("almost halfway") } +else { print("you are almost there")} //: [Previous](@previous) | page 3 of 9 | [Next: Exercise - Boolean Practice](@next)