Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ViewController.swift
- // Quizzler-iOS13
- //
- // Created by Angela Yu on 12/07/2019.
- // Copyright © 2019 The App Brewery. All rights reserved.
- //
- import UIKit
- class ViewController: UIViewController {
- @IBOutlet weak var questionLabel: UILabel!
- @IBOutlet weak var trueButton: UIButton!
- @IBOutlet weak var falseButton: UIButton!
- @IBOutlet weak var progressBar: UIProgressView!
- let quizz = [
- Question(q: "A slug's blood is green.", a: "True"),
- Question(q: "Approximately one quarter of human bones are in the feet.", a: "True"),
- Question(q: "The total surface area of two human lungs is approximately 70 square metres.", a: "True"),
- 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"),
- 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"),
- Question(q: "It is illegal to pee in the Ocean in Portugal.", a: "True"),
- Question(q: "You can lead a cow down stairs but not up stairs.", a: "False"),
- Question(q: "Google was originally called 'Backrub'.", a: "True"),
- Question(q: "Buzz Aldrin's mother's maiden name was 'Moon'.", a: "True"),
- Question(q: "The loudest sound produced by any animal is 188 decibels. That animal is the African Elephant.", a: "False"),
- Question(q: "No piece of square dry paper can be folded in half more than 7 times.", a: "False"),
- Question(q: "Chocolate affects a dog's heart and nervous system; a few ounces are enough to kill a small dog.", a: "True")
- ]
- var questionNumber = 0
- let timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(fireTimer), userInfo: nil, repeats: true)
- =
- @IBAction func answerButtonPressed(_ sender: UIButton) {
- let userAnswer = sender.currentTitle //true or false
- let actualAnswer = quizz[questionNumber].answer
- if userAnswer == actualAnswer {
- sender.backgroundColor = #colorLiteral(red: 0.3411764801, green: 0.6235294342, blue: 0.1686274558, alpha: 1)
- } else {
- sender.backgroundColor = #colorLiteral(red: 0.8078431487, green: 0.02745098062, blue: 0.3333333433, alpha: 1)
- }
- if questionNumber < quizz.count - 1 {
- questionNumber += 1
- print(questionNumber)
- } else {
- questionNumber = 0
- }
- Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateUI), userInfo: nil, repeats: true)
- }
- @objc func updateUI() {
- questionLabel.text = quizz[questionNumber].text
- trueButton.backgroundColor = UIColor.clear
- falseButton.backgroundColor = UIColor.clear
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- updateUI()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement