diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5865cd8 Binary files /dev/null and b/.DS_Store differ diff --git a/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift index 8721318..b3da1d3 100644 --- a/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/1. Exercise - Constants.xcplaygroundpage/Contents.swift @@ -3,8 +3,8 @@ 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 = 200 +print(friends) /*: Now assume you go through and remove friends that aren't active on social media. Attempt to update your `friends` constant to a lower number than it currently is. Observe what happens and then move to the next step. */ @@ -13,6 +13,6 @@ /*: 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(friends) //: page 1 of 10 | [Next: App Exercise - Step Goal](@next) diff --git a/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift index 21166b7..b7cbed8 100644 --- a/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/10. App Exercise - Percent Completed.xcplaygroundpage/Contents.swift @@ -5,12 +5,12 @@ You decide that your fitness tracking app should show the user what percentage of his/her goal has been achieved so far today. Declare a variable called `percentCompleted` and set it to 0. Do not explicity assign it a type. */ - +var percentCompleted:Double = 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/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift index b71a821..54ef0ba 100644 --- a/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/2. App Exercise - Step Goal.xcplaygroundpage/Contents.swift @@ -5,11 +5,11 @@ 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/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift index 1b6fe9b..d1485b1 100644 --- a/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/3. Exercise - Variables.xcplaygroundpage/Contents.swift @@ -3,16 +3,16 @@ 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+=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("Constants cannot change in value but variables can be changed") //: [Previous](@previous) | page 3 of 10 | [Next: App Exercise - Step Count](@next) diff --git a/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift index 4c95fb5..7472fa5 100644 --- a/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/4. App Exercise - Step Count.xcplaygroundpage/Contents.swift @@ -5,11 +5,13 @@ 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/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift index 1d38a49..0c8551f 100644 --- a/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/5. Exercise - Constant Or Variable.xcplaygroundpage/Contents.swift @@ -10,9 +10,9 @@ 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 likes=101 +var comments=12 +let yearCreated=2021 +let monthCreated=4 +let dayCreated=11 //: [Previous](@previous) | page 5 of 10 | [Next: App Exercise - Fitness Tracker: Constant or Variable?](@next) diff --git a/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift index a9bfc4b..f068197 100644 --- a/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/6. App Exercise - Constant or Variable.xcplaygroundpage/Contents.swift @@ -11,11 +11,16 @@ - Goal number of steps: The user's goal for number of steps to take each day - Average heart rate: The user's average heart rate over the last 24 hours */ - - - - - +let username="User1" +print("The name will never change") +var age=19 +print("Age changes every year") +var stepsToday=2100 +print("Steps taken every day changes") +let goalSteps = 10000 +print("The Goal Steps don't change") +var averageHeartRate=75 +print("Heart Rate average changes with moving") /*: Now go back and add a line after each constant or variable declaration. On those lines, print a statement explaining why you chose to declare the piece of information as a constant or variable. */ diff --git a/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift index 6a26c32..1cd1ab8 100644 --- a/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/7. Exercise - Types and Type Safety.xcplaygroundpage/Contents.swift @@ -3,21 +3,22 @@ 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:Double=0.0 +var secondDecimal:Double=1.0 /*: 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:Bool = true +print("Type Safety prevents assigning incompatible data types") /*: 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 str:String = "Hello" +print("Cannot assign string to double") /*: Finally, declare a variable with a whole number value. Then try to assign it to `firstDecimal`. Why won't this compile even though both variables are numbers? Print a statement to the console explaining why not, and remove the line of code that will not compile. */ - - +var whole:Int = 13 +print("Cannot assign integer to double") //: [Previous](@previous) | page 7 of 10 | [Next: App Exercise - Tracking Different Types](@next) diff --git a/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift index 1badf6b..0b44282 100644 --- a/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/8. App Exercise - Tracking Different Types.xcplaygroundpage/Contents.swift @@ -5,11 +5,14 @@ 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:Bool /*: 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 goalSteps=2000 +var stepsTaken = 1500 + //: [Previous](@previous) | page 8 of 10 | [Next: Exercise - Type Inference and Required Values](@next) diff --git a/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift b/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift index 5c81e84..8ea7ec4 100644 --- a/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift +++ b/Lab - Constants and Variables.playground/Pages/9. Exercise - Type Inference and Required Values.xcplaygroundpage/Contents.swift @@ -3,21 +3,22 @@ Declare a variable called `name` of type `String`, but do not give it a value. Print `name` to the console. Does the code compile? Remove any code that will not compile. */ +var name:String /*: Now assign a value to `name`, and print it to the console. */ - - +name="Mohamed" +print(name) /*: Declare a variable called `distanceTraveled` and set it to 0. Do not give it an explicit type. */ - +var distanceTraveled:Double = 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 //: [Previous](@previous) | page 9 of 10 | [Next: App Exercise - Percent Completed](@next) diff --git a/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift index e3db378..b70f0c4 100644 --- a/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/1. Exercise - Logical Operators.xcplaygroundpage/Contents.swift @@ -10,46 +10,46 @@ 1. `9 == 9` */ - - +true +print(9==9) /*: 2. `9 != 9` */ - - +false +print(9 != 9) /*: 3. `47 > 90` */ - - +false +print(47>90) /*: 4. `47 < 90` */ - - +true +print(47<90) /*: 5. `4 <= 4` */ - - +true +print(4<=4) /*: 6. `4 >= 5` */ - - +false +print(4>=5) /*: 7. `(47 > 90) && (47 < 90)` */ - - +false +print(47>90 && 47<90) /*: 8. `(47 > 90) || (47 < 90)` */ - - +true +print(47>90 || 47<90) /*: 9. `!true` */ - - +false +print(!true) //: page 1 of 9 | [Next: Exercise - If and If-Else Statements](@next) diff --git a/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift index 5bb5325..02eec3a 100644 --- a/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/2. Exercise - If and If-Else Statements.xcplaygroundpage/Contents.swift @@ -4,18 +4,36 @@ 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>0 && dollars<100){ + print("You've got some spending money!") +} +else{ + print("Looks to me you're rich!") +} //: [Previous](@previous) | page 2 of 9 | [Next: App Exercise - Fitness Decisions](@next) diff --git a/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift index d0d23b3..d19e7ef 100644 --- a/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/3. App Exercise - Fitness Decisions.xcplaygroundpage/Contents.swift @@ -5,11 +5,25 @@ You want your fitness tracking app to give as much encouragement as possible to your users. Create a variable `steps` equal to the number of steps you guess you've taken today. Create a constant `stepGoal` equal to 10,000. Write an if-else statement that will print "You're almost halfway there!" if `steps` is less than half of `stepGoal`, and will print "You're over halfway there!" if `steps` is greater than half of `stepGoal`. */ - - +var steps=100 +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(stepsstepGoal/10){ + 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/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift index 5db9740..21f8a74 100644 --- a/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/4. Exercise - Boolean Practice.xcplaygroundpage/Contents.swift @@ -12,7 +12,12 @@ 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. @@ -20,6 +25,9 @@ let hasVegan = true let temp = 82 let isRaining = true let isSunny = true - +let isNiceWeather = !isRaining && isSunny || temp>=82 +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/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift index 8740e75..9b59bfd 100644 --- a/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/5. App Exercise - Target Heart Rate.xcplaygroundpage/Contents.swift @@ -10,6 +10,17 @@ let targetLowerBound = 120 let targetUpperBound = 150 let currentHR = 147 - +let isInTarget:Bool,isBelowTarget:Bool,isAboveTarget:Bool +isInTarget = currentHR>targetLowerBound && currentHRtargetUpperBound +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/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift index ed3e397..704e1c5 100644 --- a/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/6. Switch Statements.xcplaygroundpage/Contents.swift @@ -3,11 +3,30 @@ 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/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift index 40f36d4..83a302b 100644 --- a/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/7. App Exercise - Heart Rate Zones.xcplaygroundpage/Contents.swift @@ -15,7 +15,20 @@ If `currentHR` is above the listed zones, print some kind of warning asking the user to slow down. */ -let currentHR = 128 - +let currentHR = 134 +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("Warning slow down!") +} //: [Previous](@previous) | page 7 of 9 | [Next: Exercise - Ternary Operator](@next) diff --git a/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift b/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift index 24cbb56..c5a4e2a 100644 --- a/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift +++ b/Lab - Control Flow.playground/Pages/8. Exercise - Ternary Operator.xcplaygroundpage/Contents.swift @@ -7,10 +7,6 @@ let number1 = 14 let number2 = 25 var largest: Int -if number1 > number2 { - largest = number1 -} else { - largest = number2 -} +largest = number1>number2 ? number1:number2 //: [Previous](@previous) | page 8 of 9 | [Next: App Exercise - Ternary Messages](@next) diff --git a/Lab - Functions.playground/Pages/1. Exercise - Create Functions.xcplaygroundpage/Contents.swift b/Lab - Functions.playground/Pages/1. Exercise - Create Functions.xcplaygroundpage/Contents.swift index 37d509b..608d757 100644 --- a/Lab - Functions.playground/Pages/1. Exercise - Create Functions.xcplaygroundpage/Contents.swift +++ b/Lab - Functions.playground/Pages/1. Exercise - Create Functions.xcplaygroundpage/Contents.swift @@ -3,11 +3,32 @@ Write a function called `introduceMyself` that prints a brief introduction of yourself. Call the function and observe the printout. */ - - +func introduceMyself() +{ print("My name is Mohamed Elkanzi")} +introduceMyself() /*: Write a function called `magicEightBall` that generates a random number and then uses either a switch statement or if-else-if statements to print different responses based on the random number generated. `let randomNum = Int.random(in: 0...4)` will generate a random number from 0 to 4, after which you can print different phrases corresponding to the number generated. Call the function multiple times and observe the different printouts. */ - - +func magicEightBall(){ + let randomNum = Int.random(in: 0...4) + if(randomNum==0) + { + print(0) + } + else if(randomNum==1) + { + print(1) + } + else if (randomNum==2){ + print(2) + } + else if(randomNum==3) + { + print(3) + } + else{ + print(4) + } +} +magicEightBall() //: page 1 of 6 | [Next: App Exercise - A Functioning App](@next) diff --git a/Lab - Functions.playground/Pages/2. App Exercise - A Functioning App.xcplaygroundpage/Contents.swift b/Lab - Functions.playground/Pages/2. App Exercise - A Functioning App.xcplaygroundpage/Contents.swift index 17808ef..b9dc4a6 100644 --- a/Lab - Functions.playground/Pages/2. App Exercise - A Functioning App.xcplaygroundpage/Contents.swift +++ b/Lab - Functions.playground/Pages/2. App Exercise - A Functioning App.xcplaygroundpage/Contents.swift @@ -8,12 +8,39 @@ A reoccurring process like this is a perfect candidate for a function. Write a function called `incrementSteps` after the declaration of `steps` below that will increment `steps` by one and then print its value. Call the function multiple times and observe the printouts. */ var steps = 0 - - +func incrementSteps (value: Int)-> Int{ + let newStep = value + 1 + print(newStep) + return newStep +} +steps=incrementSteps(value: steps) +steps=incrementSteps(value: steps) +steps=incrementSteps(value: steps) /*: Similarly, if you want to regularly provide progress updates to your user, you can put your control flow statements that check on progress into a function. Write a function called `progressUpdate` after the declaration of `goal` below. The function should print "You're off to a good start." if `steps` is less than 10% of `goal`, "You're almost halfway there!" if `steps` is less than half of `goal`, "You're over halfway there!" if `steps` is less than 90% of `goal`, "You're almost there!" if `steps` is less than `goal`, and "You beat your goal!" otherwise. Call the function and observe the printout. Remember, you can convert numbers using the appropriate Int or Double initializer. */ let goal = 10000 - - +func progressUpdate(value: Int){ + let progress=((Double(value)/Double(goal))*100) + if(progress<10){ + print("You're off to a good start") + } + else if(progress>=10 && progress<50 ){ + print("You're almost halfway there!") + } + else if(progress>=50 && progress<90){ + print("You're over halfway there!") + } + else if(progress>=90 && progress < 100){ + print("You're almost there!") + } + else{ + print("You beat your goal!") + } +} +progressUpdate(value: 4000) +progressUpdate(value: 5000) +progressUpdate(value: 8800) +progressUpdate(value: 9000) +progressUpdate(value: 10000) //: [Previous](@previous) | page 2 of 6 | [Next: Exercise - Parameters and Argument Labels](@next) diff --git a/Lab - Functions.playground/Pages/3. Exercise - Parameters and Argument Labels.xcplaygroundpage/Contents.swift b/Lab - Functions.playground/Pages/3. Exercise - Parameters and Argument Labels.xcplaygroundpage/Contents.swift index 33158a5..92bb4f2 100644 --- a/Lab - Functions.playground/Pages/3. Exercise - Parameters and Argument Labels.xcplaygroundpage/Contents.swift +++ b/Lab - Functions.playground/Pages/3. Exercise - Parameters and Argument Labels.xcplaygroundpage/Contents.swift @@ -3,16 +3,20 @@ Write a new introduction function called `introduction`. It should take two `String` parameters, `name` and `home`, and one `Int` parameter, `age`. The function should print a brief introduction. I.e. if "Mary," "California," and 32 were passed into the function, it might print "Mary, 32, is from California." Call the function and observe the printout. */ - - +func introduction(name: String, home: String, age: Int){ + print("\(name), \(age), is from \(home)") +} +introduction(name: "Mohamed", home: "Riffa", age: 38) /*: Write a function called `almostAddition` that takes two `Int` arguments. The first argument should not require an argument label. The function should add the two arguments together, subtract 2, then print the result. Call the function and observe the printout. */ - - +func almostAddition(_ n1: Int, n2: Int){ + print(n1+n2-2) +} +almostAddition(5, n2: 7) /*: Write a function called `multiply` that takes two `Double` arguments. The function should multiply the two arguments and print the result. The first argument should not require a label, and the second argument should have an external label, "by", that differs from the internal label. Call the function and observe the printout. */ - +func multiply(n: Double, m: Double) //: [Previous](@previous) | page 3 of 6 | [Next: App Exercise - Progress Updates](@next) diff --git a/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift b/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift index cd86d9d..7d97276 100644 --- a/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift +++ b/Lab - Introduction.playground/Pages/1. Exercise - Use Playgrounds.xcplaygroundpage/Contents.swift @@ -10,14 +10,14 @@ print("How to use playgrounds to make writing Swift fun and simple") /*: Now print your own phrases to the console. Pick one of your favorite songs. Use your knowledge of the `print` function to display the song title and artist. */ - - +print("I believe I can fly") +print("R. Kelly") /*: Use multiple `print` functions to write out some of the lyrics to the song. */ - - - +print("I believe I can fly") +print("I believe I can touch the sky") +print("I think about it every night and day") /*: _Copyright © 2018 Apple Inc._ diff --git a/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift index 8c68750..5bb964e 100644 --- a/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/1. Exercise - Basic Arithmetic.xcplaygroundpage/Contents.swift @@ -3,28 +3,32 @@ 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 height = 20 +let width = 10 +var area = height*width +print (area) /*: You decide that you'll divide your shed into two rooms. You want to know if dividing it equally will leave enough room for some of your larger storage items. Create a `roomArea` constant that is the result of dividing `area` in half. Print out the result. */ - - +let roomArea = area/2 +print(roomArea) /*: Create a `perimeter` constant whose value equals `width` plus `width` plus `height` plus `height`, then print out the result. */ - - +let perimeter = width + width + height + height +print(perimeter) /*: Print what you would expect the result of integer division of 10 divided by 3 to be. Create a constant, `integerDivisionResult` that is the result of 10 divided by 3, and print the value. */ - +let integerDivionResult = 10/3 +print(integerDivionResult) /*: 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, 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,16 +37,20 @@ *circumference = 2 * pi * radius.* */ let pi = 3.1415927 - - +let radius = 5.0 +var diameter = 2*radius +var circumference = 2*pi*radius +print(diameter) +print(circumference) /*: Create an integer constant. Using the remainder operator, set its value to the remainder of 12 divided by 5. */ - +let remainder:Int = 12%5 /*: Create two integer constants, `even` and `odd` and set them to any even integer and any odd integer, respectively. For each, print the remainder of dividing the value by 2. Looking at the results, how do you think you could use the remainder operator to determine if an integer is even or odd? */ - - +let even:Int=2,odd:Int=1 +print(even%2) +print(odd%2) //: page 1 of 8 | [Next: App Exercise - Fitness Calculations](@next) diff --git a/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift index 7384367..3e988bb 100644 --- a/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/2. App Exercise - Fitness Calculations.xcplaygroundpage/Contents.swift @@ -5,16 +5,22 @@ 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=77,heartRate2=88,heartRate3=99 +let addHR = heartRate1+heartRate2+heartRate3 +let averageHR = addHR/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=77,heartRate2D:Double=88,hearRate3D:Double=99 +let addedHRD=hearRate3D+heartRate2D+heartRate1D +let averageHRD=addedHRD/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:Double=3467,goal:Double=10000 +let percentGoal = steps/goal * 100 +print(percentGoal) //: [Previous](@previous) | page 2 of 8 | [Next: Exercise - Compound Assignment](@next) diff --git a/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift index b0c97b5..5dfdafa 100644 --- a/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/3. Exercise - Compound Assignment.xcplaygroundpage/Contents.swift @@ -3,8 +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 x=10 +print(x) +x+=5 +print(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. @@ -16,7 +20,17 @@ Print the balance of your piggy bank after each step. */ - +var piggyBank=0 +piggyBank+=10 +print(piggyBank) +piggyBank+=20 +print(piggyBank) +piggyBank/=2 +print(piggyBank) +piggyBank*=3 +print(piggyBank) +piggyBank-=3 +print(piggyBank) diff --git a/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift index 881654a..67c5e8f 100644 --- a/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/4. App Exercise - Counting.xcplaygroundpage/Contents.swift @@ -5,13 +5,15 @@ 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/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift index e8378a0..aeda15b 100644 --- a/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/5. Exercise - Order of Operations.xcplaygroundpage/Contents.swift @@ -3,21 +3,22 @@ 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/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift index 1f2189c..d3e2db2 100644 --- a/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/6. App Exercise - Complex Fitness Calculations.xcplaygroundpage/Contents.swift @@ -5,13 +5,13 @@ 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 hr1:Double=61,hr2:Double=62,hr3:Double=63 +let averageHR=(hr1+hr2+hr3)/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) //: [Previous](@previous) | page 6 of 8 | [Next: Exercise - Numeric Type Conversion](@next) diff --git a/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift index 93698b8..2d61eda 100644 --- a/Lab - Operators.playground/Pages/7. Exercise - Numeric Type Conversion.xcplaygroundpage/Contents.swift +++ b/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:Int=10 +let y:Double=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("In the first operation, y is converted to 3") +print("In the second operation x is converted to 10.0") //: [Previous](@previous) | page 7 of 8 | [Next: App Exercise - Converting Types](@next) diff --git a/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift b/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift index 5de2f53..ed8be37 100644 --- a/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift +++ b/Lab - Operators.playground/Pages/8. App Exercise - Fitness Conversions.xcplaygroundpage/Contents.swift @@ -7,8 +7,9 @@ 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=5500,goal:Int=10000 +let percentGoal:Double = Double(steps)/Double(goal) +print(percentGoal) /*: _Copyright © 2018 Apple Inc._ diff --git a/Lab - Strings.playground/Pages/1. Exercise - String Basics.xcplaygroundpage/Contents.swift b/Lab - Strings.playground/Pages/1. Exercise - String Basics.xcplaygroundpage/Contents.swift index d17ab77..639ccf2 100644 --- a/Lab - Strings.playground/Pages/1. Exercise - String Basics.xcplaygroundpage/Contents.swift +++ b/Lab - Strings.playground/Pages/1. Exercise - String Basics.xcplaygroundpage/Contents.swift @@ -3,8 +3,8 @@ Create a `name` constant and assign it a string literal representing your name. */ - - +let name = "Mohamed" +print(name) /*: Create a `favoriteQuote` constant and assign it the following string literal: @@ -15,12 +15,16 @@ - callout(Example): If your favorite quote is "The grass is always greener on the other side" the value of `favoriteQuote` should be such that printing `favoriteQuote` results in the following: * `My favorite quote is "The grass is always greener on the other side."` */ - - +let favoriteQuote = "my favorite quote is \"What goes around comes around\"" +print(favoriteQuote) /*: Write an if-else statement that prints "There's nothing here" if `emptyString` is empty, and "It's not as empty as I thought" otherwise. */ let emptyString = "" - +if emptyString.isEmpty{ + print("There's nothing here") +}else{ + print("It's not as empty as I thought") +} //: page 1 of 5 | [Next: Exercise - Concatenation and Interpolation](@next) diff --git a/Lab - Strings.playground/Pages/2. Exercise - Concatenation and Interpolation.xcplaygroundpage/Contents.swift b/Lab - Strings.playground/Pages/2. Exercise - Concatenation and Interpolation.xcplaygroundpage/Contents.swift index 2bbe7f2..c17b007 100644 --- a/Lab - Strings.playground/Pages/2. Exercise - Concatenation and Interpolation.xcplaygroundpage/Contents.swift +++ b/Lab - Strings.playground/Pages/2. Exercise - Concatenation and Interpolation.xcplaygroundpage/Contents.swift @@ -3,13 +3,16 @@ Create a `city` constant and assign it a string literal representing your home city. Then create a `state` constant and assign it a string literal representing your home state. Finally, create a `home` constant and use string concatenation to assign it a string representing your home city and state (i.e. Portland, Oregon). Print the value of `home`. */ - - +let city = "Riffa" +let state = "Southern State" +let home = city + ", " + state +print(home) /*: Use the compound assignment operator (`+=`) to add `home` to `introduction` below. Print the value of `introduction`. */ -var introduction = "I live in" - +var introduction = "I live in " +introduction += home +print (introduction) /*: Declare a `name` constant and assign it your name as a string literal. Then declare an `age` constant and give it your current age as an `Int`. Then print the following phrase using string interpolation: @@ -18,6 +21,7 @@ var introduction = "I live in" Insert `name` where indicated, and insert a mathematical expression that evaluates to your current age plus one where indicated. */ - - +let name = "Mohamed" +let age:Int=37 +print("My name is \(name) and after my next birthday I will be \(age+1) years old") //: [Previous](@previous) | page 2 of 5 | [Next: App Exercise - Notifications](@next) diff --git a/Lab - Strings.playground/Pages/3. App Exercise - Notifications.xcplaygroundpage/Contents.swift b/Lab - Strings.playground/Pages/3. App Exercise - Notifications.xcplaygroundpage/Contents.swift index abb8e54..16a7310 100644 --- a/Lab - Strings.playground/Pages/3. App Exercise - Notifications.xcplaygroundpage/Contents.swift +++ b/Lab - Strings.playground/Pages/3. App Exercise - Notifications.xcplaygroundpage/Contents.swift @@ -7,8 +7,10 @@ Create `firstName` and `lastName` constants and assign them string literals representing a user's first name and last name, respectively. Create a `fullName` constant that uses string concatenation to combine `firstName` and `lastName`. Print the value of `fullName`. */ - - +let firstName = "Mohamed" +let lastName = "Elkanzi" +let fullName = firstName + " " + lastName +print(fullName) /*: Occasionally users of your fitness tracking app will beat previous goals or records. You may want to notify them when this happens for encouragement purposes. Create a new constant `congratulations` and assign it a string literal that uses string interpolation to create the following string: @@ -18,6 +20,7 @@ */ let previousBest = 14392 let newBest = 15125 - +let congratulations = "Congratulations, \(fullName)! You beat your previous daily high score of \(previousBest) steps by walking \(newBest) steps yesterday!" +print(congratulations) //: [Previous](@previous) | page 3 of 5 | [Next: Exercise - String Equality and Comparison](@next) diff --git a/Lab - Strings.playground/Pages/4. Exercise - String Equality and Comparison.xcplaygroundpage/Contents.swift b/Lab - Strings.playground/Pages/4. Exercise - String Equality and Comparison.xcplaygroundpage/Contents.swift index 3ee86db..46af1b3 100644 --- a/Lab - Strings.playground/Pages/4. Exercise - String Equality and Comparison.xcplaygroundpage/Contents.swift +++ b/Lab - Strings.playground/Pages/4. Exercise - String Equality and Comparison.xcplaygroundpage/Contents.swift @@ -3,8 +3,16 @@ Create two constants, `nameInCaps` and `name`. Assign `nameInCaps` your name as a string literal with proper capitalization. Assign `name` your name as a string literal in all lowercase. Write an if-else statement that checks to see if `nameInCaps` and `name` are the same. If they are, print "The two strings are equal", otherwise print "The two strings are not equal." */ - - +let nameInCaps = "MOHAMED" +let name = "mohamed" +if(nameInCaps == name) +{ + print("The two strings are equal") +} +else +{ + print("The two strings are not equal") +} /*: Write a new if-else statement that also checks to see if `nameInCaps` and `name` are the same. However, this time use the `lowercased()` method on each constant to compare the lowercase version of the strings. If they are equal, print the following statement using string interpolations: @@ -14,13 +22,22 @@ - " and are not the same." */ - +if(nameInCaps.lowercased() == name.lowercased()) +{ + print(nameInCaps.lowercased() + " and " + name.lowercased() + " are the same") +} +else{ + print(nameInCaps.lowercased() + " and " + name.lowercased() + " are not the same") +} /*: Imagine you are looking through a list of names to find any that end in "Jr." Write an if statement below that will check if `junior` has the suffix "Jr.". If it does, print "We found a second generation name!" */ let junior = "Cal Ripken Jr." - +if(junior.hasSuffix("Jr.")) +{ + print("We found a second generation name!") +} /*: Suppose you are trying to find a document on your computer that contains Hamlet's famous soliloquy written by Shakespeare. You write a simple app that will check every document to see if it contains the phrase "to be, or not to be". You decide to do part of this with the `contains(_:)` method. Write an if statement below that will check if `textToSearchThrough` contains `textToSearchFor`. If it does, print "I found it!" Be sure to make this functionality case insensitive. @@ -28,11 +45,14 @@ let junior = "Cal Ripken Jr." import Foundation let textToSearchThrough = "To be, or not to be--that is the question" let textToSearchFor = "to be, or not to be" - +if(textToSearchThrough.lowercased().contains(textToSearchFor.lowercased())) +{ + print("I found it!") +} /*: Print to the console the number of characters in your name by using the `count` property on `name`. */ - +print(name.count) //: [Previous](@previous) | page 4 of 5 | [Next: App Exercise - Password Entry and User Search](@next) diff --git a/Lab - Strings.playground/Pages/5. App Exercise - Password Entry and User Search.xcplaygroundpage/Contents.swift b/Lab - Strings.playground/Pages/5. App Exercise - Password Entry and User Search.xcplaygroundpage/Contents.swift index e396836..3e0c4ad 100644 --- a/Lab - Strings.playground/Pages/5. App Exercise - Password Entry and User Search.xcplaygroundpage/Contents.swift +++ b/Lab - Strings.playground/Pages/5. App Exercise - Password Entry and User Search.xcplaygroundpage/Contents.swift @@ -9,7 +9,12 @@ let storedUserName = "TheFittest11" let storedPassword = "a8H1LuK91" let enteredUserName = "thefittest11" let enteredPassword: String = "a8H1Luk9" - +if(storedPassword.lowercased() == enteredPassword.lowercased() && storedPassword == enteredPassword){ + print("You are now logged in!") +} +else{ + print("Please check your user name and password and try again") +} /*: Now that users can log in, they need to be able to search through a list of users to find their friends. This might normally be done by having the user enter a name, and then looping through all user names to see if a user name contains the search term entered. You'll learn about loops later, so for now you'll just work through one cycle of that. Imagine you are searching for a friend whose user name is StepChallenger. You enter "step" into a search bar and the app begins to search. When the app comes to the user name "stepchallenger," it checks to see if "StepChallenger" contains "step." @@ -19,7 +24,13 @@ let enteredPassword: String = "a8H1Luk9" import Foundation let userName = "StepChallenger" let searchName = "step" - +if(userName.lowercased().contains(searchName.lowercased())) +{ + print("Found " + userName) +} +else{ + print("Not found") +} /*: