Skip to content

all about functions #491

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

Open
wants to merge 1 commit into
base: master
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
78 changes: 53 additions & 25 deletions MyPlayground.playground/Pages/main.xcplaygroundpage/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@





func frozen(){
print("Let it go!")
}
frozen()



Expand All @@ -27,8 +29,11 @@
*/
// write your code here



func frozenAgain(){
let now = "Let it go!"
print(now)
}
frozenAgain()



Expand All @@ -38,6 +43,10 @@
*/
// write your code here

func favoriteCharacter(name: String){
print("My favorite character is \(name).")
}
favoriteCharacter(name: "Ralph")



Expand All @@ -50,8 +59,10 @@
// write your code here


let newCharacter = favoriteCharacter(name: "King Kong")


var bestCharacter = favoriteCharacter(name: "Penelope")
var cheese = favoriteCharacter(name: "Mr. Hankey")



Expand All @@ -61,9 +72,11 @@
// write your code here


func problems(num: Int){
print("I got \(num) problems but Swift ain't one")
}



problems(num: 99)



Expand All @@ -72,19 +85,22 @@
*/
// write your code here



func favBand(band: String, num: Int){
print("My #\(num) favorite band is \(band).")

}
favBand(band: "CKY", num: 1)



/*: question7
### 7. The code below is broken. Can you identify which line has an error and fix it so that it works again? Uncomment the code below before starting.
*/
//func badFavoriteBand(bandName: String, position: Int) {
// print("My #\(position) favorite band is \(bandName).")
//}
//
//badFavoriteBand("The Beatles", 2)
func badFavoriteBand(bandName: String, position: Int) {
print("My #\(position) favorite band is \(bandName).")
}

badFavoriteBand(bandName: "The Beatles", position: 2)



Expand All @@ -95,11 +111,11 @@
/*: question8
### 8. This code is broken, too. Assume the call to the function is correct. What's broken about the function definition? Can you fix it? Uncomment the code below before starting.
*/
//func alsoBadFavoriteBand(bandName: String, position: String) {
// print("My #\(position) favorite band is \(bandName)")
//}
//
//alsoBadFavoriteBand(bandName: "Blink-182", position: 42)
func alsoBadFavoriteBand(bandName: String, position: Int) {
print("My #\(position) favorite band is \(bandName)")
}

alsoBadFavoriteBand(bandName: "Blink-182", position: 42)



Expand All @@ -112,7 +128,11 @@
*/
// write your code here

func madLib(name: String, noun: String, preposition: String){
print("To \(noun) and \(preposition), \(name)!")
}

madLib(name: "King Kong", noun: "City", preposition: "on" )



Expand All @@ -123,9 +143,12 @@
*/
// write your code here

func resuce()->String{
return "Buzz Lightyear to the resuce!"

}



resuce()



Expand All @@ -135,18 +158,23 @@
// write your code here


func num()-> Int{
return 347
}



num()

/*: question12
### 12. Create a function that takes in a characters name. This function will return back a `String` as follows: "To infinity and beyond, <character name>!". The character name should be returned uppercased.
*/
// write your code here




func buzz(name: String)-> String{
return "To infinity and beyond, \(name)!"

}
buzz(name: "Woody")


//: Click [here](https://github.com/learn-co-curriculum/swift-allAboutFunctions-lab/blob/solution/MyPlayground.playground/Pages/solution.xcplaygroundpage/Contents.swift) for a link to the solution.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Binary file not shown.