Topic : make a TOEIC test APP
APP content :
1. Question number : 20 (with random sequence)
2. Test score = 5 / question, maximum = 100
3. At the end, push “Start Test” reset to default

TOECI Test APP

1st step : make the APP flow

2nd step : spend too much time to set a random matrix > <|||

 // Random the questions sequence and creat the quesion sequence array
var arr = Array(0...19).shuffled()
lazy var sequenceArray = Array(arr)

3rd step : set button action and change to next question, also make many mistake, too much name and confused

 // If player push button 1
@IBAction func choice1Push(_ sender: Any) {
let qnumber = sequenceNumber
let answerNumber = sequenceArray[(qnumber)]
let answer = rightAnswer[answerNumber]
changeFrameColor(QuestionNumber: qnumber)

if answer == "1" {
updateProgress()
}
if sequenceNumber >= (questions.count-1) {
qLabel.text?.append("Score: \(scoreNumber)")
qLabel.isHidden = false
}
}
// If player push button 2
@IBAction func choice2Push(_ sender: Any) {
let qnumber = sequenceNumber
let answerNumber = sequenceArray[(qnumber)]
let answer = rightAnswer[answerNumber]
changeFrameColor(QuestionNumber: qnumber)

if answer == "2" {
updateProgress()
}
if sequenceNumber >= (questions.count-1) {
qLabel.text?.append("Score: \(scoreNumber)")
qLabel.isHidden = false
}
}

Response from GPT
這段程式碼是一個簡單的測驗App,讓使用者回答問題並得到分數。這裡是對這段程式碼的評價和改進建議:

評價:

  • 優點:這段程式碼很短,功能單一,易於理解和維護。
  • 缺點:這段程式碼中的類名 ViewController 表示這個類負責太多事情,應該考慮將其拆分為多個類。

改進建議:

  • 考慮使用 UITableView 來顯示問題和選項,而不是使用多個單獨的 UI 元件。
  • 創建一個 Question 類別,用於存儲問題和答案,而不是使用兩個分開的數組。
  • 將測試邏輯分離到一個獨立的類中,以提高可重用性和測試性。

Next time should add login page and score result ranking pages.

--

--

ChengWen Lee
彼得潘的 Swift iOS / Flutter App 開發教室

After worked in office for 22 years, it is time to know the real word. I would like to be a Digital Nomad (Working everywhere) and on the way now~~~