diff --git a/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Contents.swift b/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Contents.swift index 821321d..359ed9d 100644 --- a/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Contents.swift +++ b/Student Resources/1 - Getting Started/1 - Introduction to Swift and Playgrounds/lab/Lab - Introduction.playground/Contents.swift @@ -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) \ No newline at end of file +//:page 14 of 16 | [Next: Exercise: Go! Fight! Win!](@next) 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..8289b03 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 @@ -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:") @@ -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._ */ diff --git a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Contents.swift b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Contents.swift index d86a552..5fbac3f 100644 --- a/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Contents.swift +++ b/Student Resources/1 - Getting Started/2 - Constants, Variables, and Data Types/lab/Lab - Constants and Variables.playground/Contents.swift @@ -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) /*: */ @@ -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) 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..57c0f9b 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 @@ -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) 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..c688573 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 @@ -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 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..53c499b 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 @@ -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) 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..4ecb74c 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,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) 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..2c933ec 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,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) 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..dcae825 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 @@ -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 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..6f33f80 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,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") 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..d1bb4f8 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,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) 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..682f1a1 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 @@ -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) 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..b1f1218 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,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) diff --git a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Contents.swift b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Contents.swift index 73f34bf..e3b5c10 100644 --- a/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Contents.swift +++ b/Student Resources/1 - Getting Started/3 - Operators/lab/Lab - Operators.playground/Contents.swift @@ -11,27 +11,36 @@ /*: Create a `perimeter` constant whose value equals `width` plus `width` plus `height` plus `height`. Print out the result. */ +let width = 100 +let height = 250 +let area = width * height +print(area) +let perimeter = width + width + height + height +print(perimeter) /*: Print out what you think 10 + 2 * 5 evaluates to. Then print out the actual expression (i.e., `print(10 + 2 * 5)`) */ - +print(20) +print(10 + 2 * 5) /*: In a separate statement, add in the necessary parentheses so that addition takes place before multiplication. */ - +print((10 + 2) * 5) /*: Create a constant, `divisionResult`, that's the result of 10 divided by 3. Print the constant's value. */ - +let divisionResult = 10 / 3 +print(divisionResult) /*: Create a constant, `moreAccurateResult`, that's also the result of 10 divided by 3, but includes the repeating decimal. Print this value. */ - +let moreAccurateResult: Double = 10 / 3 +print(moreAccurateResult) /*: Given the value pi (3.1415927), create a `radius` constant with a value of 5.0. Use the following equations to calculate the diameter and circumference of a circle, and print the results: @@ -40,19 +49,34 @@ *circumference = 2 * pi * radius.* */ - +let pi = 3.1415927 +let radius = 5.0 +let diameter = 2 * radius +print(diameter) +let circumference = 2 * pi * radius +print(circumference) /*: Declare a variable whose value begins at 10. Using addition and the compound assignment operator, update the value to 15. Using multiplication and compound assignment, update the value to 30. Print out the variable's value after each assignment. */ +var value = 10 +print(value) +value += 5 +print(value) +value *= 2 +print(value) /*: Create an integer constant with a value of 10, and a double constant with a value of 3.2. Cast the `Double` to an `Int`, then multiply it by the integer constant. Print out the resulting value. */ - +let value1 = 10 +let value2 = 3.2 +let result = Int(value2) * value1 +print(result) /*: Create an integer constant. Using the modulus operator, set its value to the remainder of 12 divided by 5. */ - +let value3: Int = 12 % 5 +print(value3) 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..cc9eab0 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 @@ -3,27 +3,38 @@ 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. */ - + print("floor quotient 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) /*: 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: @@ -33,6 +44,12 @@ *circumference = 2 * pi * radius.* */ let pi = 3.1415927 +let radius = 5.0 +let diameter = 2 * radius +let circumference = 2 * pi * radius +print(radius) +print(diameter) +print(circumference) //: page 1 of 8 | [Next: App Exercise - Fitness Calculations](@next) 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..eae5b70 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,31 @@ 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 = 70 +let heartRate2 = 80 +let heartRate3 = 90 +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 = 70 +let heartRate2D: Double = 80 +let heartRate3D: Double = 90 +let addedHRD = heartRate1D + heartRate2D + heartRate3D +let averageHRD = addedHRD / 3 +print (averageHRD) +print("Yes, because the constants this time defined as Double not Int") /*: 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 = 3_467 +let goal: Double = 10_000 +let percentOfGoal = (steps / goal) * 100 +print(percentOfGoal) //: [Previous](@previous) | page 2 of 8 | [Next: Exercise - Compound Assignment](@next) 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..cd4fead 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 @@ -3,6 +3,12 @@ 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 +print(value) +value += 5 +print(value) +value *= 2 +print(value) /*: @@ -16,7 +22,18 @@ Print the balance of your piggy bank after each step. */ - +var piggyBank = 0 +print(piggyBank) +piggyBank += 10 +print(piggyBank) +piggyBank += 20 +print(piggyBank) +piggyBank /= 2 +print(piggyBank) +piggyBank *= 3 +print(piggyBank) +piggyBank -= 3 +print(piggyBank) 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..b28a895 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,16 @@ 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 = 50 +distance /= 3 +print(distance) //: [Previous](@previous) | page 4 of 8 | [Next: Exercise - Order of Operations](@next) 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..407b4b1 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 @@ -3,21 +3,23 @@ Print out what you think 10 + 2 * 5 evaluates to. Then print out the actual expression (i.e. `print(10 + 2 * 5)`) */ - +print(20) +print(10 + 2 * 5) /*: 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) 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..62a564f 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 @@ -5,13 +5,19 @@ 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. */ - +let heartRate1D: Double = 70 +let heartRate2D: Double = 80 +let heartRate3D: Double = 90 +let averageHR = (heartRate1D + heartRate2D + heartRate3D) / 3 +print (averageHR) /*: One feature you might want to give users is to display their current body temperature. Create a constant `tempInFahrenheit` equal to 98.6. 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.0 / 9.0) +print(tempInCelsius) //: [Previous](@previous) | page 6 of 8 | [Next: Exercise - Numeric Type Conversion](@next) 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..694605a 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 @@ -3,16 +3,20 @@ 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 = 10 +let 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 multipliedAsIntegers displays product of 2 Int operators while multipliedAsDoubles displays product of 2 Double operators") //: [Previous](@previous) | page 7 of 8 | [Next: App Exercise - Converting Types](@next) 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..85758e5 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 @@ -7,7 +7,10 @@ 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 = 5_000 +let goal: Int = 10_000 +let percentOfGoal: Double = (Double(steps) / Double(goal)) * 100 +print(percentOfGoal) /*: diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift index e3db378..ed74ecf 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift @@ -10,46 +10,55 @@ 1. `9 == 9` */ - +print(true) +print(9 == 9) /*: 2. `9 != 9` */ - +print(false) +print(9 != 9) /*: 3. `47 > 90` */ - +print(false) +print (47 > 90) /*: 4. `47 < 90` */ - +print(true) +print(47 < 90) /*: 5. `4 <= 4` */ - +print(true) +print(4 <= 4) /*: 6. `4 >= 5` */ - +print(false) +print(4 >= 5) /*: 7. `(47 > 90) && (47 < 90)` */ - +print(false) +print((47 > 90) && (47 < 90)) /*: 8. `(47 > 90) || (47 < 90)` */ - +print(true) +print((47 > 90) || (47 < 90)) /*: 9. `!true` */ - +print(false) +print(!true) //: page 1 of 9 | [Next: Exercise - If and If-Else Statements](@next) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift index 5bb5325..0951563 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift @@ -4,18 +4,35 @@ Imagine you're creating a machine that will count your money for you and tell you how wealthy you are based on how much money you have. A variable `dollars` has been given to you with a value of 0. Write an if statement that prints "Sorry, kid. You're broke!" if `dollars` has a value of 0. Observe what is printed to the console. */ var dollars = 0 - +if(dollars == 0){ + print("Sorry, kid. You're broke!") +} /*: `dollars` has been updated below to have a value of 10. Write an an if-else statement that prints "Sorry, kid. You're broke!" if `dollars` has a value of 0, but prints "You've got some spending money!" otherwise. Observe what is printed to the console. */ dollars = 10 - +if(dollars == 0){ + print("Sorry, kid. You're broke!") +} +else{ + print("You've got some spending money!") +} /*: `dollars` has been updated below to have a value of 105. Write an an if-else-if statement that prints "Sorry, kid. You're broke!" if `dollars` has a value of 0, prints "You've got some spending money!" if `dollars` is less than 100, and prints "Looks to me like you're rich!" otherwise. Observe what is printed to the console. */ dollars = 105 +if(dollars == 0){ + print("Sorry, kid. You're broke!") +} +else if (dollars < 100){ + print("You've got some spending money!") +} +else { + print("Looks to me like you're rich!") +} + //: [Previous](@previous) | page 2 of 9 | [Next: App Exercise - Fitness Decisions](@next) 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..27d6658 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 @@ -5,11 +5,26 @@ 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 = 300 +let stepGoal = 10_000 - +if (steps < (stepGoal / 2)){ + print("You're almost halfway there!") +} +else { +print("You're over 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 ( (Double(steps) < (Double(stepGoal) * 0.1))){ + print("Way to get a good start today!") +} +else if (steps < (stepGoal / 2)){ + print("You're almost halfway there!") +} +else { +print("You're over halfway there!") +} //: [Previous](@previous) | page 3 of 9 | [Next: Exercise - Boolean Practice](@next) 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..6e5539c 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 @@ -13,6 +13,13 @@ let hasFish = true let hasPizza = false let hasVegan = true +if ((hasFish || hasPizza) && hasVegan){ + print("Let's go!") +} +else{ + print("Sorry, we'll have to think of somewhere 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. @@ -21,5 +28,10 @@ let temp = 82 let isRaining = true let isSunny = true +let isNiceWeather = !(isRaining) || temp <= 82 || isSunny +if(isNiceWeather){ + print("I'm going for a walk!") +} + //: [Previous](@previous) | page 4 of 9 | [Next: App Exercise - Target Heart Rate](@next) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift index 8740e75..ab19012 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift @@ -11,5 +11,18 @@ let targetLowerBound = 120 let targetUpperBound = 150 let currentHR = 147 +let isInTarget = (currentHR > targetLowerBound) && (currentHR < targetUpperBound) +let isBelowTarget = currentHR <= targetLowerBound +let isAboveTarget = currentHR >= targetUpperBound + +if(isInTarget){ + print("You're right on track!") +} +else if (isBelowTarget){ + print("You're doing great, but try to push it a bit!") +} +else{ + print("You're on fire! Slow it down just a bit.") +} //: [Previous](@previous) | page 5 of 9 | [Next: Exercise - Switch Statements](@next) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift index ed3e397..4dc020f 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift @@ -3,11 +3,26 @@ Imagine you're on a baseball team nearing the end of the season. Create a `leaguePosition` constant with a value of 1. Using a `switch` statement, print "Champions!" if the `leaguePosition` is 1, "Runners up" if the value is 2, "Third place" if the value is 3, and "Bad season!" in all other cases. */ - +let leaguePosition = 1 +switch leaguePosition { +case 1: + print("Champions!") +case 2: + print("Runners up") +case 3: + print("Third Place") +default: + print("Bad season!") +} /*: Write a new `switch` statement that prints "Medal winner" if `leaguePosition` is within the range of 1-3. Otherwise, print "No medal awarded". */ - +switch leaguePosition { +case 1,2,3: + print("Medal winner") +default: + print("No medal awarded") +} //: [Previous](@previous) | page 6 of 9 | [Next: App Exercise - Heart Rate Zones](@next) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift index 40f36d4..e4cbc19 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift @@ -16,6 +16,21 @@ If `currentHR` is above the listed zones, print some kind of warning asking the user to slow down. */ let currentHR = 128 +switch currentHR { + case _ where currentHR >= 100 && currentHR <= 120: + print("You are in the Very Light zone. Activity in this zone helps with recovery.") + case _ where currentHR >= 121 && currentHR <= 140: + print("You are in the Light zone. Activity in this zone helps improve basice endurance and fat burning") + case _ where currentHR >= 141 && currentHR <= 160: + print("You are in the Moderate zone. Activity in this zone helps improve aerobic fitness.") + case _ where currentHR >= 161 && currentHR <= 180: + print("You are in the Hard zone. Activity in this zone increases maximum performance capacity for shorter sessions..") + case _ where currentHR >= 181 && currentHR <= 200: + print("You are in the Maximum zone. Activity in this zone helps fit athletes develop speed.") + default: + print("You are in the Exterme Lowest zone, stand up") +} + //: [Previous](@previous) | page 7 of 9 | [Next: Exercise - Ternary Operator](@next) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift index 24cbb56..c370122 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift @@ -6,11 +6,12 @@ let number1 = 14 let number2 = 25 -var largest: Int -if number1 > number2 { - largest = number1 -} else { - largest = number2 -} - +// var largest: Int +// if number1 > number2 { +// largest = number1 +// } else { +// largest = number2 +// } +number1 > number2 ? number1 : number2 +print(number1 > number2 ? number1 : number2) //: [Previous](@previous) | page 8 of 9 | [Next: App Exercise - Ternary Messages](@next) diff --git a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/9. App Exercise - Ternary Messages.xcplaygroundpage/Contents.swift b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/9. App Exercise - Ternary Messages.xcplaygroundpage/Contents.swift index 5c86dde..4422fac 100644 --- a/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/9. App Exercise - Ternary Messages.xcplaygroundpage/Contents.swift +++ b/Student Resources/1 - Getting Started/4 - Control Flow/lab/Lab - Control Flow.playground/Pages/9. App Exercise - Ternary Messages.xcplaygroundpage/Contents.swift @@ -8,13 +8,14 @@ let stepGoal = 10000 let steps = 3948 -if steps < stepGoal / 2 { - print("Almost halfway!") -} else { - print("Over halfway!") -} - - +// if steps < stepGoal / 2 { +// print("Almost halfway!") +// } else { +// print("Over halfway!") +// } + +steps < stepGoal / 2 ? "Almost halfway!" : "Over halfway!" +print(steps < stepGoal / 2 ? "Almost halfway!" : "Over halfway!") /*: _Copyright © 2018 Apple Inc._