diff --git a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift index b84a717..05e6584 100644 --- a/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift +++ b/MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift @@ -24,63 +24,69 @@ let b = 32 /*: Question 1 ### 1. Print the result of a greater than or equal to b */ -// write your code here - +print(a>=b) /*: Question 2 ### 2. Print the result of a modulo b is equal to zero */ -// write your code here - +print(a % b == 0) /*: Question 3 ### 3. Print the result of y times b less than or equal to a */ -// write your code here - +print(y * b <= a) /*: Question 4 ### 4. Print the inverse of a greater than or equal to b */ -// write your code here - +print(!(a >= b)) /*: Question 5 ### 5. Print "true" if a modulo b is equal to zero */ -// write your code here - +if a % b == 0 { + print("true") +} /*: Question 6 ### 6. Print "true" if a divided by b is greater than x */ -// write your code here - +if Double(a / b) > x { + print("true") +} /*: Question 7 ### 7. Print "true" if y divided by x is greater than three, otherwise print false */ -// write your code here - +if Double(y) / x > 3 { + print("true") +} else { + print("false") +} /*: Question 8 ### 8. Print "true" if y is greater than x and a divided by b is greater than 9 */ -// write your code here - +if Double(y) > x && (a / b) > 9 { + print("true") +} /*: Question 9 ### 9. Write a function "isGreater" that takes two Int arguments and returns true if the first is greater than the second and false if they're not */ -// write your code here - - +func isGreater(num1: Int, num2: Int) -> Bool { + if num1 > num2 { + return true + } else { + return false + } +} @@ -88,15 +94,34 @@ let b = 32 /*: Question 10 ### 10. Write a function "isForceWith" that takes a String argument and returns true if the argument is the name of someone with whom the force is strong, and otherwise returns false. People who have the force are Luke, Leia, Anakin, Obi Wan, Yoda, Vader. */ -// write your code here - +func isForceWith(force: String) -> Bool { + if force == "Luke" { + return true + } else if force == "Leia" { + return true + } else if force == "Anakin" { + return true + } else if force == "Obi Wan" { + return true + } else if force == "Yoda" { + return true + } else if force == "Vader" { + return true + } else { + return false + } +} /*: Question 11 ### 11. Create a function where the two arguments represent different bank account (one of those bank accounts is yours). What type should these arguments be if we are to then perform some math operations on them? Setup a conditional that will add 10 to your funds and minus 10 from the other funds (bank account) if the other account won't go negative if we were to take 10 dollars from it. */ -// write your code here - +func bankTransfer(bank1: Double, bank2: Double) { + if bank2 >= 10 { + bank1 + 10 + bank2 - 10 + } +}