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..6f1dda9 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 @@ -12,11 +12,15 @@ print("How to use playgrounds to make writing Swift fun and simple") /*: Now print your own phrases to the console. Pick one of your favorite songs. Use your knowledge of the `print` function to display the song title and artist. */ + print("Sway, Michael Buble") /*: Use multiple `print` functions to write out some of the lyrics to the song. */ - +print("When marimba rhythms start to play") +print("Dance with me, make me sway") +print("Like a lazy ocean hugs the shore") +print("Hold me close, sway me more") //:page 14 of 16 | [Next: Exercise: Go! Fight! Win!](@next) \ No newline at end of file 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..bd06ff2 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 @@ -11,12 +11,16 @@ 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("Sway, Michael Buble") + /*: Use multiple `print` functions to write out some of the lyrics to the song. */ - - +print("When marimba rhythms start to play") +print("Dance with me, make me sway") +print("Like a lazy ocean hugs the shore") +print("Hold me close, sway me more") /*: 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..20b3003 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 @@ -3,27 +3,30 @@ 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 = 75 /*: 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 = 50 /*: 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("You can not change a value of a constant, switch to var to make it mutable") /*: Declare a variable `age` and set it to your own age. Print `age` to the console. */ - +var age = 26 +print(age) /*: Now pretend you just had a birthday, and update the `age` variable accordingly. Print `age` to the console. */ +age = 27 +print(age) /*: */ @@ -32,19 +35,108 @@ /*: 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 x = 1.1 +print(x) +x = 2.2 +print(x) +x = 3.3 +print(x) +x = 4.4 +print(x) /*: Create a Boolean variable and set it to `true`. Print the variable, then assign it a value of `false`, and print it again. */ - +var y = true +print(y) +y = false +print(y) /*: 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 x1 = 0 +var x2 = 0.0 +x1 = Int(x2) + +/*: + Create a variable integer with a value of 1,000,000,000. Format it using commas, so it's easier to read. + */ + var z = 1000000000 + +import Foundation +let numberFormatter = NumberFormatter() +numberFormatter.numberStyle = .decimal +print(numberFormatter.string(from: NSNumber(value:z))!) + +/*: + ## 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 = 75 + +/*: + 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 = 50 + +/*: + 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("You can not change a value of a constant, switch to var to make it mutable") +/*: + Declare a variable `age` and set it to your own age. Print `age` to the console. + */ +var age = 26 +print(age) + +/*: + Now pretend you just had a birthday, and update the `age` variable accordingly. Print `age` to the console. + */ + +age = 27 +print(age) +/*: + + */ + + +/*: + 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 x = 1.1 +print(x) +x = 2.2 +print(x) +x = 3.3 +print(x) +x = 4.4 +print(x) + +/*: + Create a Boolean variable and set it to `true`. Print the variable, then assign it a value of `false`, and print it again. + */ +var y = true +print(y) +y = false +print(y) + +/*: + 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 x1 = 0 +var x2 = 0.0 +x1 = Int(x2) /*: Create a variable integer with a value of 1,000,000,000. Format it using commas, so it's easier to read. */ + var z = 1000000000 + +import Foundation +let numberFormatter = NumberFormatter() +numberFormatter.numberStyle = .decimal +print(numberFormatter.string(from: NSNumber(value:z))!) 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..e41c812 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 @@ -3,16 +3,16 @@ 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 = 75 /*: - 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. + 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 = 50 /*: 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("You can not change a value of a constant, switch to var to make it mutable") //: 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..7d4016e 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,13 @@ 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 +percentCompleted = 0 /*: Imagine that partway through the day a user has taken 3,467 steps out of the 10,000 step goal. This means he/she is 34.67% of the way to his/her goal. Assign 34.67 to `percentCompleted`. Does the code compile? Go back and explicity assign a type to `percentCompleted` that will allow the code to compile. */ - +percentCompleted = 34.67 /*: 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..1ad0504 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,12 @@ 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..76e9aff 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 = 19 +print(schooling) /*: Now imagine you just completed an additional year of school, and update the `schooling` variable accordingly. Print `schooling` to the console. */ - +schooling = schooling + 1 +print(schooling) /*: Does the above code compile? Why is this different than trying to update a constant? Print your explanation to the console using the `print` function. */ - +print("You can change the value of a variable") //: [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..d927390 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 @@ -10,7 +10,11 @@ For each of the metrics above, declare either a constant or a variable and assign it a value corresponding to a hypothetical post. Be sure to use proper naming conventions. */ - +var numLikes = 100 +var numComments = 10 +let year = 2020 +let month = 4 +let day = 12 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..7c5f9c4 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 @@ -13,7 +13,16 @@ */ - +let name = "Omnia" +print("A user's profile name should not change") +var age = 26 +print("The user age will automatically increment by years") +var steps = 1286 +print("The steps count changes along the day") +var goal = 10000 +print("The user might want to change his goal according to his progress") +var HRate = 94 +print("The user avg heart rate might change") /*: 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..cd42ce8 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.1 +var secondDecimal = 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 +print("we 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 s = "omnia" +//firstDecimal = s +print("we 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 n = 100 +//firstDecimal = n +print("we 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..e67e2ba 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,21 @@ You have declared a number of constants and variables to keep track of fitness information. Declare one more variable with a boolean value called `hasMetStepGoal`. */ + 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 goal = 10000 + var steps = 1286 +import Foundation + +let numberFormatter = NumberFormatter() +numberFormatter.numberStyle = .decimal +print(numberFormatter.string(from: NSNumber(value:goal))!) +print(numberFormatter.string(from: NSNumber(value:steps))!) + //: [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..791c2de 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) /*: Now assign a value to `name`, and print it to the console. */ - +name = "omnia" +print(name) /*: Declare a variable called `distanceTraveled` and set it to 0. Do not give it an explicit type. */ - +var distanceTraveled : Double +distanceTraveled = 0 /*: Now assign a value of 54.3 to `distanceTraveled`. Does the code compile? Go back and set an explicit type on `distanceTraveled` so the code will compile. */ - +distanceTraveled = 54.3 +print(distanceTraveled) //: [Previous](@previous) | page 9 of 10 | [Next: App Exercise - Percent Completed](@next) 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..16ac639 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 @@ -8,30 +8,39 @@ // Order of operations // Modulo // Numeric Type Conversion +let width = 100 +let height = 250 +let area = width*height +print(area) + /*: Create a `perimeter` constant whose value equals `width` plus `width` plus `height` plus `height`. Print out the result. */ - +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(60) +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 = 10.0/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,31 @@ *circumference = 2 * pi * radius.* */ - +let pi = 3.1415927 +let radius = 5.0 +let diameter = 2 * radius +let circumference = 2 * pi * radius +print(diameter) +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 x = 10 +x = x + 5 +print(x) +x = x * 2 +print(x) /*: 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. */ - +var y = 10 +var z = 3.2 +print(Int(z)*y) /*: Create an integer constant. Using the modulus operator, set its value to the remainder of 12 divided by 5. */ - +var c = 12 % 5 +print(c) 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..dd94e73 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,26 +3,39 @@ 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(3.33) +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 + double10 = 10 + let double3: Double + double3 = 3 + divisionResult = double10/double3 + print(divisionResult) /*: @@ -32,7 +45,11 @@ *circumference = 2 * pi * radius.* */ -let pi = 3.1415927 - +let pi = 3.1415927 +let radius = 5.0 +let diameter = 2 * radius +let circumference = 2 * pi * 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..c14cc3d 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,30 @@ 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 = 65 +let heartRate3 = 80 +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 = 60.0 +let heartRate2D = 65.0 +let heartRate3D = 80.0 +let addedHRD = heartRate1 + heartRate2 + heartRate3 +let averageHRD = addedHR / 3 +print(averageHRD) /*: 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 = 3467.0 +let goal = 10000.0 +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..b342d71 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,7 +3,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 x = 10 +x = x + 5 +print(x) +x = x * 2 +print(x) /*: 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. @@ -17,7 +21,17 @@ Print the balance of your piggy bank after each step. */ - +var piggyBank = 0.0 +piggyBank = piggyBank + 10 +print(piggyBank) +piggyBank = piggyBank + 20 +print(piggyBank) +piggyBank = piggyBank/2 +print(piggyBank) +piggyBank = piggyBank*3 +print(piggyBank) +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..33b9ff0 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 @@ -1,17 +1,19 @@ -/*: + /*: ## App Exercise - Counting >These exercises reinforce Swift concepts in the context of a fitness tracking app. 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 = 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 = 50.0 +print(distance/3) //: [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..6316170 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(60) +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(36) +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..bb9c95a 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,18 @@ 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 heartRate1 = 60.0 +let heartRate2 = 65.0 +let heartRate3 = 80.0 +print((heartRate1 + heartRate2 + heartRate3) / 3) /*: 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..ee862f1 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,12 +3,18 @@ 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 = Int(3.2) +let multipliedAsIntegers = x * 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 x1 = 10.0 +let y1 = 3.2 +let multipliedAsDoubles = x1 * y1 +print(multipliedAsDoubles) /*: Are the values of `multipliedAsIntegers` and `multipliedAsDoubles` different? Print a statement to the console explaining why. 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..ef174db 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 = 5000 +let goal = 10000 +let percentOfGoal = (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..b242100 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,41 +10,50 @@ 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)) /*: 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..8eeb767 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,34 @@ 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..d32bdf3 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 = 900 +let stepGoal = 10000 +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 (steps < stepGoal/10) { + 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..502b5c4 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 @@ -12,7 +12,11 @@ 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 +25,9 @@ let temp = 82 let isRaining = true let isSunny = true +if ((!isRaining || temp >= 82) && isSunny) { + 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..31d0ebb 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,16 @@ let targetLowerBound = 120 let targetUpperBound = 150 let currentHR = 147 +var isBelowTarget = (currentHR < targetLowerBound) +var isAboveTarget = (currentHR > targetUpperBound) + +if (isBelowTarget) { + print("You're doing great, but try to push it a bit!") +} else if (isAboveTarget) { + print("You're on fire! Slow it down just a bit.") +} else { + print("You're right on track!") +} + //: [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..0c68026 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 @@ -4,10 +4,20 @@ 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..9b05e41 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 @@ -17,5 +17,13 @@ */ let currentHR = 128 +switch currentHR { +case 100..<120: print("You are in the Very Light zone. Activity in this zone helps with recovery.") +case 121..<140: print("You are in the Light zone. Activity in this zone helps improve basice endurance and fat burning.") +case 141..<160: print("You are in the Moderate zone. Activity in this zone helps improve aerobic fitness.") +case 161..<180: print("You are in the Hard zone. Activity in this zone increases maximum performance capacity for shorter sessions.") +case 181..<200: print("You are in the Maximum zone. Activity in this zone helps fit athletes develop speed.") +default: print("You are on Fire!! You should slow down") +} //: [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..b8e55dd 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,14 @@ let number1 = 14 let number2 = 25 -var largest: Int +/*var largest: Int if number1 > number2 { largest = number1 } else { largest = number2 -} +}*/ + +var largest = (number1 > number2 ? number1 : number2) +print(largest) //: [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..f5fa86a 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,11 +8,8 @@ let stepGoal = 10000 let steps = 3948 -if steps < stepGoal / 2 { - print("Almost halfway!") -} else { - print("Over halfway!") -} +print(steps < stepGoal / 2 ? "Almost halfway!" : "Over halfway!") + /*: