Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created and completed Swift Fundamentals #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
Binary file added .DS_Store
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,9 @@
//: Next, learn how programmers can leave notes in code.
//:
//:[Previous](@previous) | page 3 of 7 | [Next: Comments](@next)
4 + 5
9 - 3




Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@
//: Take a deep breath and move on to the next page.
//:
//:[Previous](@previous) | page 4 of 7 | [Next: When Things Go Wrong 😰](@next)
/* HELLO
THIS
IS
HAJAR
WRITING
*/
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
//: This playground page, for example, has an error in it.
//:
//: 👈 Notice the red error symbol to the left of the line below. This is how a playground tells you where a problem is.
1000 / 0
1000 / 10

//: Since there is an error, the playground stops running your code.\
//: Notice that there are no results displayed in the sidebar. 👉
2 + 2
Expand All @@ -19,3 +20,7 @@
//: Next, read all about your very recent past.
//:
//:[Previous](@previous) | page 6 of 7 | [Next: Wrapup](@next)
1000 / 5



Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,9 @@
//:
//: For negative numbers use the minus sign:
-1200
/*:
Notice how the numbers also show up in the gray area to the right? 👉

That area is called the _results sidebar_. As you add or change code, the playground runs your code again and updates the results in the sidebar.

- experiment:
- Click a line of code to move the cursor there.
- Type to start editing code.
- Change the numbers a few times.
- Add a few new numbers, each on a separate line.\
Notice that every time you make a change the results are updated in the sidebar.




Next, find out how to put the results sidebar to better use.

[Previous](@previous) | page 2 of 7 | [Next: Calculations](@next)
*/
5
5
4



Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@
(150 * 10) - (1000 + 40)
//: - callout(Exercise): Using the code above as a reference, use let statements to define constants to better solve your friend’s problem.\
//:Add your code below. To help you get started, the constant `numberOfTickets` is already defined.
let numberOfTickets = 150

//:
//:[Previous](@previous) | page 10 of 14 | [Next: Exercise: Lottery Tickets](@next)
let numberOfTickets = 150
let TicketPrice = 10
let RoomRentalFee = 1000
let PosterCost = 40
let TotalTicketValue = 150 * 10
let TotalExpenses = 1000 + 40
let TotalIncomeOfShow = (150 * 10) - (1000 + 40)

Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,23 @@ let programmersCut = profit / 10 // This is the answer you want to get over 100!
let friendsCut = profit - programmersCut

//:[Previous](@previous) | page 11 of 14 | [Next: Exercise: What Fits on Your iPhone?](@next)
let theTicketsSold = 900
let theTicketPrice = 3
let thePrintingCosts = 18
let theAdvertising = 40

// Total takings
let theTotalTakings = theTicketPrice * theTicketsSold

// Jackpot
let Thejackpot = theTotalTakings / 2

// Expenses
let TheTotalExpenses = thePrintingCosts + theAdvertising

// Profit
let TheProfit = theTotalTakings - Thejackpot - TheTotalExpenses

// Distribution
let theProgrammersCut = TheProfit / 10 // This is the answer you want to get over 100! 👉
let theFriendsCut = TheProfit - theProgrammersCut
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
_Hint_: Do all of your calculations in megabytes (MB).
*/





//:[Previous](@previous) | page 12 of 14 | [Next: Exercise: Fixing Your Morning](@next)
let IphoneStorage = 8 * 1000 // convert from GB to MB
let IphoneOcuppiedStorage = 3 * 1000 //convert from GB to MB
let IphoneFreeStorage = IphoneStorage - IphoneOcuppiedStorage
let OneMinute = 150
let MinutesTakenToFullStorage = OneMinute * IphoneFreeStorage

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

- callout(Exercise): Create a constant for each activity you do in the morning before leaving home: things like `brushTeeth`, `uploadPhotos`, `chooseClothes`, `shower`, `goJogging`, `finishHomework`, `fixLunch`, and so on. Think about how many minutes each activity usually takes, and assign that value to each constant.
*/
let brushTeeth = 3

// Add more here...

//: - callout(Exercise): Find the total time of all the activities by adding up the constants. Try to adjust the values or add more activities until the total time looks reasonably close to the actual amount of time you spend getting ready on an average day.
Expand All @@ -20,6 +20,7 @@ let brushTeeth = 3




/*:
See what happens to your total time spent getting ready if you tweak the durations of the different activities. How short of a shower would you have to take in order to have more time to message your friends? Or go for a longer run? How much more time would you need if you decided to spend as long as you wanted doing all the activities you like best?

Expand All @@ -31,3 +32,24 @@ let brushTeeth = 3


//:[Previous](@previous) | page 13 of 14 | [Next: Exercise: Good Names](@next)
//1st ex
let brushTeeth = 2
let uploadPhotos = 0
let chooseClothes = 10
let shower = 15
let goJogging = 20
let finishHomework = 50
let fixLunch = 10


//2nd ex
let totalTime = brushTeeth + uploadPhotos + chooseClothes + shower + goJogging + finishHomework + fixLunch


//3rd ex:
let thingsIhaveToDo = shower + brushTeeth + finishHomework
let thingsIlikeToDo = goJogging + chooseClothes + uploadPhotos
let thingsIhateToDo = fixLunch



Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,15 @@ let rhso = co - lhso
_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE._
*/
//:[Previous](@previous) | page 14 of 14
let CountOfOranges = 14
let CountOfWatermelons = 3
let OrangesWeight = 100
let WatermelonsWeight = 200
let TotalOranges = CountOfOranges * OrangesWeight
let TotalWatermelons = CountOfWatermelons * WatermelonsWeight
let Total = OrangesWeight + WatermelonsWeight
let EachSide = Total / 2
let LeftHandSideOranges = EachSide / OrangesWeight
let RightHandSideOranges = CountOfOranges - LeftHandSideOranges


Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,16 @@ let numberOfTurtles = 2 + 1

let numberOfHamsters = 1 + 1

let totalNumberOfAnimals = numberOfDogs + numberOfCats + numberOfTurtles + numberOfHamsters
let numberOfPigs = 1

let numberOfFishes = 1

let numberOfSnakes = 1

let totalNumberOfAnimals = numberOfDogs + numberOfCats + numberOfTurtles + numberOfHamsters + numberOfPigs + numberOfFishes + numberOfSnakes

let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters + numberOfPigs

let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters

//: - experiment: There are even more changes in the pets expected at the pet show.\
//:To add new kinds of animals, add new lines of code that define new constants. (To add a new line of code just click on a blank line in the area above and start typing.)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,14 @@ let totalNumberOfMammals = numberOfDogs + numberOfCats + numberOfHamsters
//: Once you’re finished experimenting, move ahead.
//:
//:[Previous](@previous) | page 4 of 14 | [Next: Typing Names and Autocompletion](@next)
let TheNumberOfDogs = 6 + 2

let TheNumberOfCats = 5 - 1

let TheNumberOfTurtles = 2 + 1

let TheNumberOfHamsters = 1 + 1

let TheTotalNumberOfAnimals = TheNumberOfDogs + TheNumberOfCats + TheNumberOfTurtles + TheNumberOfHamsters
let TheTotalNumberOfMammals = TheNumberOfDogs + TheNumberOfCats + TheNumberOfHamsters

Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,22 @@
//: Could there be a better way to solve this problem? Think about it for a minute or two, then move on.
//:
//:[Previous](@previous) | page 2 of 14 | [Next: Pet Problem Recap](@next)
// Number Of Dogs
6

// Number Of Cats
5

// Number Of Turtles
2

// Number Of Hamsters
1

// Total Number Of Animals
6 + 5 + 2 + 1

// Total Number Of Mammals
6 + 5 + 1


Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,24 @@ let finishedMessage = username + " " + likesYourPostMessage
//: Next, find out how building strings by adding them can get complicated.
//:
//:[Previous](@previous) | page 5 of 16 | [Next: Fill In The Blanks](@next)
// Declare a firstName constant

let firstName : String = "Hajar" //by defult the compiler will know its a string from the double quotation but i write (: Sring) just in case :)


// Declare a lastName constant

let lastName : String = "Alatawi"


// Combine the strings into a fullName constant

let fullName : String = firstName + " " + lastName


// Combine your first name with likesYourPostMessage

let likesYourPostMessage2 : String = "\(firstName) likes your post"



Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ let traditionalGreeting = "Hello, world!"
//: - experiment: Practice by declaring `favoriteMovie` and `favoriteSong` string constants for your favorite movie and song:
// Declare a favoriteMovie constant


// Declare a favoriteSong constant


//: Next, take a string-based trip around the world.
//:
//:[Previous](@previous) | page 3 of 16 | [Next: Unicode](@next)
// Declare a favoriteMovie constant
let favoriteMovie = "Home Alone"

// Declare a favoriteSong constant
let favoriteSong = "Imagine by: John Lennon"
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ let customerOrderSix = "小笼包"
- callout(Exercise):
Make sure the server repeats the order correctly *without* copying and pasting or retyping any of the orders.
*/

let serverResponseToTableTwo = "Let me make sure I've got this right: <Enter the Order Here>"

let tableTwoResponse = "Perfect, merci bien."
Expand All @@ -34,3 +35,39 @@ let tableTwoResponse = "Perfect, merci bien."

//:
//:[Previous](@previous) | page 14 of 16 | [Next: Exercise: Go! Fight! Win!](@next)
// T1:

let theserverResponseToTableOne = "Let me make sure I've got this right: \(customerOrderOne). Is that everything?"

let tableOneResponse1 = "Yes, thank you!"


// T2:

let theserverResponseToTableTwo = "Let me make sure I've got this right: \(customerOrderTwo). Is that everything?"

let tableTwoResponse2 = "Perfect, merci bien."


// T3:
let serverResponseToTableThree = "Let me make sure I've got this right: \(customerOrderThree) . Is that everything?"

let tableThreeResponse = "yeah, thanks!"

// T4:

let serverResponseToTableFour = "Let me make sure I've got this right: \(customerOrderFour) . Is that everything?"

let tableFourResponse = "Yes, thank you!"

// T5:

let serverResponseToTableFive = "Let me make sure I've got this right: \(customerOrderFive) . Is that everything?"

let tableFiveResponse = "Yup, thanks!"

// T6:

let serverResponseToTableSix = "Let me make sure I've got this right: \(customerOrderSix) . Is that everything?"

let tableSixResponse = "yes, thanks!"
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@
_THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE._
*/
//:[Previous](@previous) | page 16 of 16
let IphoneStorage = 8 * 1000 // convert from GB to MB
let IphoneOcuppiedStorage = 3 * 1000 //convert from GB to MB
let IphoneFreeStorage = IphoneStorage - IphoneOcuppiedStorage
let OneMinute = 150
let MinutesTakenToFullStorage = OneMinute * IphoneFreeStorage
let result = "You can record \(MinutesTakenToFullStorage) more minutes of video."
print (result)

Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ let song = "\(refrain)\n\(refrain)\nYes, \(refrain)"

//:
//:[Previous](@previous) | page 15 of 16 | [Next: Exercise: Displaying Values](@next)
let theschoolName = "King Abdulaziz"
let refrain_ = "hmm hmm HMMM hm-hmm \(theschoolName) hmm hmm HMMMMM"

let thesong = "\(refrain_)\n\(refrain_)\nYes, \(refrain_)"

print(thesong)
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,14 @@ let newline = "Making new lines"
- experiment: Make a new string constant that is a list of the things you’ve learned, with each entry on a new line. Make sure you add the result to the playground page so that you can see the list properly.
*/





//:
//:[Previous](@previous) | page 13 of 16 | [Next: Exercise: A Restaurant](@next)
let thignsIHaveLearned = """
\(constants)
\(unicode)
\(combining)
\(interpolation)
\(escaping)
\(newline)
"""
print (thignsIHaveLearned)
Loading