Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 3.12 KB | None | 0 0
  1. //
  2. //  ViewController.swift
  3. //  Quizzler-iOS13
  4. //
  5. //  Created by Angela Yu on 12/07/2019.
  6. //  Copyright © 2019 The App Brewery. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10.  
  11. class ViewController: UIViewController {
  12.    
  13.    
  14.    
  15.     @IBOutlet weak var questionLabel: UILabel!
  16.     @IBOutlet weak var trueButton: UIButton!
  17.     @IBOutlet weak var falseButton: UIButton!
  18.     @IBOutlet weak var progressBar: UIProgressView!
  19.    
  20.     let quizz = [
  21.         Question(q: "A slug's blood is green.", a: "True"),
  22.         Question(q: "Approximately one quarter of human bones are in the feet.", a: "True"),
  23.         Question(q: "The total surface area of two human lungs is approximately 70 square metres.", a: "True"),
  24.         Question(q: "In West Virginia, USA, if you accidentally hit an animal with your car, you are free to take it home to eat.", a: "True"),
  25.         Question(q: "In London, UK, if you happen to die in the House of Parliament, you are technically entitled to a state funeral, because the building is considered too sacred a place.", a: "False"),
  26.         Question(q: "It is illegal to pee in the Ocean in Portugal.", a: "True"),
  27.         Question(q: "You can lead a cow down stairs but not up stairs.", a: "False"),
  28.         Question(q: "Google was originally called 'Backrub'.", a: "True"),
  29.         Question(q: "Buzz Aldrin's mother's maiden name was 'Moon'.", a: "True"),
  30.         Question(q: "The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.", a: "False"),
  31.         Question(q: "No piece of square dry paper can be folded in half more than 7 times.", a: "False"),
  32.         Question(q: "Chocolate affects a dog's heart and nervous system; a few ounces are enough to kill a small dog.", a: "True")
  33.        
  34.     ]
  35.     var questionNumber = 0
  36.    
  37.     let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(fireTimer), userInfo: nil, repeats: true)
  38.    =
  39.     @IBAction func answerButtonPressed(_ sender: UIButton) {
  40.         let userAnswer = sender.currentTitle //true or false
  41.         let actualAnswer = quizz[questionNumber].answer
  42.         if userAnswer == actualAnswer {
  43.             sender.backgroundColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
  44.            
  45.         } else {
  46.             sender.backgroundColor = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)
  47.            
  48.         }
  49.        
  50.         if  questionNumber < quizz.count - 1 {
  51.             questionNumber += 1
  52.             print(questionNumber)
  53.            
  54.         } else {
  55.             questionNumber = 0
  56.         }
  57.        
  58.         Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateUI), userInfo: nil, repeats: true)
  59.        
  60.    
  61.     }
  62.     @objc func updateUI() {
  63.        
  64.         questionLabel.text = quizz[questionNumber].text
  65.         trueButton.backgroundColor = UIColor.clear
  66.         falseButton.backgroundColor = UIColor.clear
  67.        
  68.        
  69.     }
  70.    
  71.     override func viewDidLoad() {
  72.         super.viewDidLoad()
  73.         updateUI()
  74.        
  75.     }
  76.    
  77.  
  78. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement