Hey everyone i'm really new to coding and am loving it so far, i've made a pretty basic quiz app although it does have just over 100 questions, the game sets an alert at the end of all 100 questions but I want it to end at say 10 or 30 and so on, heres some code would I insert here or where my questions are? thanks in advanced
let answer = question.answers[indexPath.row]
if checkAnswer(answer: answer, question: question) {
if let index = gameModels.firstIndex(where: { $0.text == question.text }) {
if index (gameModels.count + 1) {
//next question
let nextQuestion = gameModels[index+1]
print("\(gameModels.shuffle())")
currentQuestion = nil
configureUI(question: nextQuestion)
self.scoreBoard += 1
self.scoreLabel.text = String(scoreBoard)
}
else {
//end of game
let alert = UIAlertController(title: "Done", message: "You beat the game", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))
present(alert, animated: true)
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hey everyone! Still quite new at coding so any help would be much appreciated, so I have a quiz app and there may be over 100 questions but once it gets to a certain number it sends an alert, after the alert I want it to go back to the main screen, thoughts?
if questionsAsked = 4 {
// alert user that game is over
let alert = UIAlertController(title: "Done", message: "You beat the game", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Dismiss", style: .cancel, handler: nil))
present(alert, animated: true)
}
Hey there, pretty new to coding with swift but I have a quiz app which has about 100 questions in an index path, and want the game to end at say 30 questions, any way I could do this? Any help would be greatly appreciated
Hey everyone really struggling with this one, I have a quiz app however I need the questions to not repeat. My var is:
var gameModels = [Question]()
And then my index:
if index (gameModels.count + 1) {
//next question
print("\(gameModels.shuffle())")
let nextQuestion = gameModels[index+1]
currentQuestion = nil
configureUI(question: nextQuestion)
self.scoreBoard += 1
self.scoreLabel.text = String(scoreBoard)
questionsAsked += 1
}
Any help would be greatly appreciated, cheers!