- Optionals
- Dictionaries
- Conditionals
- If
- Switch
- Loops
- Reuse
- Functions
- Closures
- Task 1 — Optionals
- Create a variable which hold an optional value and assign
nil
to it - Print the variable if it is not
nil
- Assign the same variable a NOT
nil
value - Print the variable if it is not
nil
- Create a variable which hold an optional value and assign
- Task 2 — Loops
- Create an array with 5 names
- Print the names in the array using a loop
- Task 3 — Reuse
- Create a function that takes a price and a discount value and returns the price after the discount
- Print the value of the function when the price=100 & discount=0.5
- Print the value of the function when the price=200 & discount=0.25
- Task 4 — Conditionals
- Create a variable that holds a student GPA
- If the GPA is above 3 print nice ;)
- If the GPA is below 3 print not nice :(
- If the GPA is 3 print nice and not nice :)
- Task 5 — Conditionals (Bonus 😉)
- There is no universal rule about when to use if-else and when to use switch. Sometimes, we prefer one over the other just because of readability. Let's say, you typically get a bonus at the end of each year. Now you are making a plan for your next travel destination. Here is the plan:
- If you get a bonus of $10000 (or more), you will travel to Paris and London.
- If the bonus is between $5000 and $9999, you will travel to Tokyo.
- If the bonus is between $1000 and $4999, you will travel to Bangkok.
- If the bonus is less than $1000, you just stay home.
- Write a Swift program that making a plan for your next travel destination based on the bonus at the end of each year
- There is no universal rule about when to use if-else and when to use switch. Sometimes, we prefer one over the other just because of readability. Let's say, you typically get a bonus at the end of each year. Now you are making a plan for your next travel destination. Here is the plan:
Tuesday 28 September