如何制作测验应用程序,其中得分最高的答案显示正确的警报。

How to make quiz app where answer with highest score displays the correct alert.

我最初问的是 "how to make quiz app that has no right answer" 这个问题,后来我了解到那不是正确的方法。我想做的是做一个测验,根据你选择的答案,建议听某位艺术家。我给所有的按钮分配了不同的分数,所以如果你的分数在某个范围内,你就会被推荐给某个艺术家。然后我突然想到,如果我使用一个分数以外的衡量标准,我可以使分数更容易计算。所以我给了每个艺术家自己的类别,根据你按下的按钮,那个类别会得到一个分数。

例如

 else if quuis > 3 { let alert = UIAlertController(title: "Check Out Quis Christ", message: "Quis Christ has a style of hip hip reminiscent of the golden age of lyricism and hard beats. Quis makes every line count with hard rhymes that any hip hop purist can enjoy", preferredStyle: .alert)

        let restartAction = UIAlertAction(title: "restart", style: .default
            , handler: { UIAlertAction in self.startOver()})
        alert.addAction(restartAction)
        present(alert, animated: true, completion: nil)
        startButton.isHidden = false
    }else if mojoI > 3 { let alert = UIAlertController(title: "Check Out Mojofree", message: "MoJo Free has a trap soul sound that feeds your curiosity if SZA and Erykah Badu came together and fused. She has raw lyricism and smooth voice that makes for a great listening experience ", preferredStyle: .alert)

        let restartAction = UIAlertAction(title: "restart", style: .default
            , handler: { UIAlertAction in self.startOver()})
        alert.addAction(restartAction)
        present(alert, animated: true, completion: nil)
        startButton.isHidden = false

    }else if billyI > 3 { let alert = UIAlertController(title: "Check Out Billypalmtrees", message: "Billypalmtrees has a rap style that can be compared to the great lupe fiasco with witty wordplay and infectious flow. He also is a hybrid artist who can also sing with smooth voice that you can sit back and enjoy", preferredStyle: .alert)

        let restartAction = UIAlertAction(title: "restart", style: .default
            , handler: { UIAlertAction in self.startOver()})
        alert.addAction(restartAction)
        present(alert, animated: true, completion: nil)
        startButton.isHidden = false

    }else if rebelI > 3 { let alert = UIAlertController(title: "Check Out Rebel Kuzco", message: "Rebel Kuzco has a new age rap style that keeps your nodding your head and singing along to any hit that plays from him. With catchy hooks complimented by high energy rhymes makes for a great listening experience.", preferredStyle: .alert)

        let restartAction = UIAlertAction(title: "restart", style: .default
            , handler: { UIAlertAction in self.startOver()})
        alert.addAction(restartAction)
        present(alert, animated: true, completion: nil)
        startButton.isHidden = false
    }

我运行遇到的问题是只有10道题,我规定如果分数大于3,建议美工,但是只有10道题,还有余地分数足够接近,以至于结果可能最终是超过 3 分的多个分数。我知道我可以将它提高到更高的阈值,但我想做的是弄清楚如何编写它以便它选择得分最高的那个,而不仅仅是得分超过某个数字的那个!

我该怎么写呢?用简单的英语,而不是代码,我脑子里的东西是

"if this score is greater than this, and this, and this, and this, then show this alert."

入门指南:

`

class Question {
let questionText = ""    
let answer = 0
}

`

然后在您的 ViewController 中将按钮连接到 IB 操作。给每个按钮一个不同的标签。也可以在IB Action中提问:

 let newQuestion = Question()
    if sender.tag == 1 {
    //User picked answer 1
    newQuestion.answer = 1

    }

如果对于 2,3,4

,则执行 else

那应该让你朝着正确的方向前进