定義 function練習

Weiling Chang
Jul 28, 2017 · 2 min read
  1. 找一首自己喜歡,讓自己一秒落淚的情歌歌詞,利用 print 將歌詞印出。
  2. 找出重覆的段落,將它定義成 function,讓自己不用輸入重覆的歌詞。
  3. 修改 function 裡的歌詞,創作自己獨一無二的改編版。

最近很喜歡這首歌:

func smile(number: String){
print(“想看你笑 想和你鬧”)
print(“想擁你入我懷抱”)
print(“上\(number)秒紅著臉在爭吵”)
print(“下\(number)秒轉身就能和好”)
}
func cry(number: String){
print(“不怕你哭 不怕你叫”)
print(“因為你是我的驕傲”)
print(“\(number)雙眼睛追著你亂跑”)
print(“\(number)顆心早已經準備好”)
}
func onetime(love: String){
print(“\(love)次就好”)
print(“我帶你去看天荒地老”)
print(“在陽光燦爛的日子裡開懷大笑”)
print(“在自由自在的空氣裡吵吵鬧鬧”)
print(“你可知道 我唯一的想要”)
}
func theworld(){
print(“世界還小 我陪你去到天涯海角”)
print(“在沒有煩惱的角落裡停止尋找”)
print(“在無憂無慮的時光裡慢慢變老”)
print(“你可知道 我全部的心跳隨你跳”)
}

smile(number: “三”)
cry(number: “五”)
onetime(love: “八”)
theworld()
smile(number: “三”)
cry(number: “五”)
onetime(love: “八”)
theworld()

彼得潘的 Swift iOS App 開發教室

學習 Swift iOS App 開發的學生作品集

Weiling Chang

Written by

彼得潘的 Swift iOS App 開發教室

學習 Swift iOS App 開發的學生作品集

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade