# 陣列-問答題(PTT鄉民實測)

`@IBOutlet weak var countLabel: UILabel! //第幾題@IBOutlet weak var questionLabel: UILabel! //題目@IBOutlet weak var answerLabel: UILabel! //答案@IBOutlet weak var fox1: UIImageView! //未答的狐狸圖@IBOutlet weak var fox2: UIImageView! //回答問題的狐狸圖`

`struct Qna{var question = ""var answer = ""}`

`var count = 0`
`var qnaArray = [Qna(question: "3樓的樓上是幾樓？", answer: "2樓"),Qna(question: "看到哪三個數字需下跪？", answer: "118"),Qna(question: "年過30保有童貞的男性為？", answer: "魔法師"),Qna(question: "PTT戰神是？", answer: "蘇美"),Qna(question: "obov是哪個教派的教主?", answer: "母豬教"),Qna(question: "8+9=?", answer: "八家將"),Qna(question: "2沒壞,猜一字？", answer: "噓"),Qna(question: "PTT女板又名？", answer: "灑花板"),Qna(question: "Z>B是什麼意思？", answer: "利大於弊"),Qna(question: "鄉民爆料文的起始句是？", answer: "我夢到")]`

`var qnaArray = [["question":"3樓的樓上是幾樓？", "answer":"2樓"],`
`["question":"看到哪三個數字需下跪？", "answer":"118"]]`

`//秀答案@IBAction func answerBtn(_ sender: Any) {fox1.isHidden = truefox2.isHidden = falseanswerLabel.isHidden = false}`

(1)讀取陣列資料的順位+1~

(2)執行nextQuestion()函式

(3)將[有對話框的狐狸圖]隱藏~並顯示[沒對話框的狐狸圖]

`//下一題@IBAction func nextBtn(_ sender: Any) {`
`count += 1if count == 10{count = 0}nextQuestion()fox1.isHidden = falsefox2.isHidden = true}`

nextQuestion()函式裡要寫些什麼呢?

(1)questionLabel.text = qnaArray[count].question

(2)answerLabel.text = qnaArray[count].answer

(3)顯示題號(因為陣列順序是從編號0開始,所以count+1就會是現在的題號)

(4)用 answerLabel.isHidden = true 來隱藏上一題的答案

`func nextQuestion(){`
`questionLabel.text = qnaArray[count].questionanswerLabel.text = qnaArray[count].answer`
`countLabel.text = "\(count+1)"answerLabel.isHidden = true`
`}`