Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,34 @@

Create a `name` constant and assign it a string literal representing your name.
*/

//let name = "Tasneem"

/*:
Create a `favoriteQuote` constant and assign it the following string literal:

- "My favorite quote is <INSERT QUOTE HERE>."
-

Write in your own favorite quote where indicated, and be sure to include escaped quotation marks. When finished, print the value of `favoriteQuote`.

- 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 \" Never Give Up \""
//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 = ""
/*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)
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
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 = " Egypt"
let state = "Cairo"
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"
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:

- "My name is <INSERT NAME HERE> and after my next birthday I will be <INSERT AGE HERE> years old."


Insert `name` where indicated, and insert a mathematical expression that evaluates to your current age plus one where indicated.
*/


/*et name = "Tasneem"
let age = 29
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)
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

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 = "Tasneem"
let lastName = " Gameel"
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:

- "Congratulations, <INSERT USER'S FULL NAME HERE>! You beat your previous daily high score of <INSERT PREVIOUS HIGHEST STEPS HERE> steps by walking <INSERT NEW HIGHEST STEPS HERE> steps yesterday!"


Insert `fullName`, `previousBest` and `newBest` where indicated. Print the value of `congratulations`.
*/
let previousBest = 14392
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)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,17 @@

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 = "Tasneem Gameel"
let name = "tasneem gameel"

if nameInCaps == name
{
print ("The two strings are equal")
}
else
{
print ( "The two strings are not equal.")
}


/*:
Expand All @@ -14,12 +25,23 @@

- "<INSERT LOWERCASED VERSION OF `nameInCaps` HERE> and <INSERT LOWERCASED VERSION OF `name` HERE> 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!")
}


/*:
Expand All @@ -28,11 +50,18 @@ 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!")
}
else{
print ("search for another word")
}

/*:
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)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*:
/*:
## App Exercise - Password Entry and User Search

>These exercises reinforce Swift concepts in the context of a fitness tracking app.
Expand All @@ -9,6 +9,14 @@ let storedUserName = "TheFittest11"
let storedPassword = "a8H1LuK91"
let enteredUserName = "thefittest11"
let enteredPassword: String = "a8H1Luk9"
if storedUserName.lowercased() == enteredUserName.lowercased() && storedPassword == enteredPassword
{
print ("You are now logged in!")
}
else
{
print ( "Please check your user name and password and try again.")
}


/*:
Expand All @@ -19,6 +27,14 @@ let enteredPassword: String = "a8H1Luk9"
import Foundation
let userName = "StepChallenger"
let searchName = "step"
if userName.lowercased().contains(searchName.lowercased())
{
print ("yes, contains")
}
else
{
print ("No, doesn't contain")
}


/*:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,37 @@

Write a function called `introduceMyself` that prints a brief introduction of yourself. Call the function and observe the printout.
*/
func introduceMyself()
{
print("I'm tasneem gameel, teaching assistant at faculty of computer and information sciences")

}
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)
switch (randomNum)
{
case 0:
print ("0")
case 1:
print ("1")
case 2:
print ("2")
case 3:
print ("3")
case 4:
print ("4")
default:
print("Not 0..4 number")
}
}

magicEightBall()

//: page 1 of 6 | [Next: App Exercise - A Functioning App](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,57 @@
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 (_ steps: Int)
{
let steps = steps+1
print (steps)
}
incrementSteps(steps)
incrementSteps(steps)
incrementSteps(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

//i can't call the othercalls with the updated value everytime steps returns to 0
var steps = 0
func incrementSteps (_ steps: Int)-> Int
{
let steps = steps+1
print (steps)
return steps
}
let no1=incrementSteps(steps)
let no2=incrementSteps(no1)
let no3=incrementSteps(no2)

let goal = 10000.0
func progressUpdate()
{
print (" You're off to a good start.")
let tenth = goal * 0.1
if (Double)no3 < tenth
{
print (" You're almost halfway there!")
}
let half = goal * 0.5
else if (Double)no3 < half
{
print (" You're over halfway there!")
}
let ninth = goal * 0.9
else if (Double)no3 < ninth
{
print(" You're almost there!")
}
else if (Double) no3 > goal
{
print (" You beat your goal!")
}
}


//: [Previous](@previous) | page 2 of 6 | [Next: Exercise - Parameters and Argument Labels](@next)
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@
## Exercise - Parameters and Argument Labels

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 ("Hello \(name), \(age), is from \(home)")
}

print ("Tasneem","Egypt", 29)


/*:
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(_ firstNum: Int, _ secondNum: Int)
{
let result = (firstNum + secondNum)-2;
print("\(firstNum) + \(secondNum) is almost \(result)")
}

almostAddition(10 , 5)


/*:
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(_ firstNum: Int, by secondNum: Int)
{
let result = firstNum * secondNum
print ( result )

}
multiply(3, by: 2)



//: [Previous](@previous) | page 3 of 6 | [Next: App Exercise - Progress Updates](@next)
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,37 @@

Call the function a number of times, passing in different values of `steps` and `goal`. Observe the printouts and make sure what is printed to the console is what you would expect for the parameters passsed in.
*/
func progressUpdate(_ steps: Int, _ goal: Int)
{
print (" You're off to a good start.")
let tenth = Double (goal) * 0.1
let half = Double (goal) * 0.5
let ninth = Double (goal) * 0.9
if Double (steps) <= tenth
{
print (" You're almost halfway there!")
}

else if Double (steps) <= half
{
print (" You're over halfway there!")
}

else if Double (steps) <= ninth
{
print(" You're almost there!")
}
else if steps > goal
{
print (" You beat your goal!")
}

}

progressUpdate(900, 1000)
progressUpdate(1900, 1000)

}

/*:
Your fitness tracking app is going to help runners stay on pace to reach their goals. Write a function called pacing that takes four `Double` parameters called `currentDistance`, `totalDistance`, `currentTime`, and `goalTime`. Your function should calculate whether or not the user is on pace to hit or beat `goalTime`. If yes, print "Keep it up!", otherwise print "You've got to push it just a bit harder!"
Expand Down
Loading