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

Complete Problems #405

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
102 changes: 52 additions & 50 deletions MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,89 +18,91 @@ let x = 5.0
let y = 12
let a = 321
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 a / b > Int(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 y > Int(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(int1: Int, int2: Int) -> Bool {
if int1 > int2 {
return true
} else {
return false
}
}

isGreater(int1: 5, int2: 2)
isGreater(int1: 3, int2: 9)
/*: 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(name: String) -> Bool {
if name == "Luke" || name == "Leia" || name == "Anakin" || name == "Obi Wan" || name == "Yoda" || name == "Vader" {
return true
} else {
return false
}
}

isForceWith(name: "Luke")
isForceWith(name: "Chewbacca")
/*: 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 transferFunds(account1: Double, account2: Double) -> (account1: Double, account2: Double) {
var myAccount = account1
var bankAccount = account2

if account2 >= 10.0 {
myAccount += 10.0
bankAccount -= 10.0
}

return (myAccount, bankAccount)
}

var myAccount = transferFunds(account1: 525.00, account2: 21.00)
var bankAccount = transferFunds(account1: 3000.00, account2: 5.00)
/*:
Click [here](https://github.com/learn-co-curriculum/swift-conditionals-lab/blob/solution/MyPlayground.playground/Pages/solution.xcplaygroundpage/Contents.swift) for the solution.
*/
Expand Down