Last active
January 2, 2025 15:54
-
-
Save TheMuellenator/69efa8bb847c58c6bc01a82d3f30fd34 to your computer and use it in GitHub Desktop.
iOS repl.it - Variables Challenge Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var a = 5 | |
| var b = 8 | |
| var c = a | |
| a = b | |
| b = c | |
| print("a: \(a)") | |
| print("b: \(b)") | |
func exercise() {
var a = 5
var b = 8
var c = a
a = b
b = c
print("a: \(a)")
print("b: \(b)")
}
also nice to know how to do it without a 3rd variable:
a=a+b
b=a-b
a=a-b
This would not work for strings now. Would it?
var a = 1
var b = 2
var c = a
a = b
b = c
print("a: (a)")
print("b: (b)")
var a = 7
var b = 9
var c = a
b = a
a = b
print("a is = (a)")
print ("b is = (b)")
var a = 7
var b = 8
var c = a
a = b
b = c
func exercise() {
var a = 5
var b = 8
//Write your code here.
//Dont change any of the existing code.
print("a: \(b)")
print("b: \(a)")
}
it is working:))
var a = 5
var b = 7
a = a + b // 12
b = a - b // 12 - 7 = 5
a = a - b // 12 - 5 = 7
print("a: (a)")
print("b: (b)")
var a = 5
var b = 8
print("the value of a is (a)")
print("the valu of b is (b)")
var temp = a
a = b
b = temp
print("the value of a is (a)")
print("the valu of b is (b)")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My solution:
`func exercise() {
}`