Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Quizzler
- //
- // Created by Angela Yu on 25/08/2015.
- // Copyright (c) 2015 London App Brewery. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- //Place your instance variables here
- let allQuestions = QuestionBank()
- var pickedAnswer : Bool = false
- var questionNumber : Int = 0
- @IBOutlet weak var questionLabel: UILabel!
- @IBOutlet weak var scoreLabel: UILabel!
- @IBOutlet var progressBar: UIView!
- @IBOutlet weak var progressLabel: UILabel!
- override func viewDidLoad() {
- super.viewDidLoad()
- let firstQuestion = allQuestions.list[0]
- questionLabel.text = firstQuestion.questionText
- }
- @IBAction func answerPressed(_ sender: AnyObject) {
- if sender.tag == 1{
- pickedAnswer = true;
- }
- else if sender.tag == 2 {
- pickedAnswer = false;
- }
- checkAnswer()
- questionNumber = questionNumber + 1
- nextQuestion()
- }
- func updateUI() {
- }
- func nextQuestion() {
- if questionNumber <= 12 {
- questionLabel.text = allQuestions.list[questionNumber].questionText
- } else {
- let alert = UIAlertController(title: "End of Quiz!", message: "Would you like to restart?", preferredStyle: .alert)
- let restartAction = UIAlertAction(title: "Restart", style: .default, handler: { (action: UIAlertAction) in
- self.startOver()
- })
- alert.addAction(restartAction)
- present(alert, animated: true, completion: nil)
- }
- }
- func checkAnswer() {
- let correctAnswer = allQuestions.list[questionNumber].answer
- if correctAnswer == pickedAnswer {
- print("You got it!")
- } else {
- print("Wrong answer cuz :/")
- }
- }
- func startOver() {
- questionNumber = 0
- nextQuestion()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement