AlexMarchant98 AlexMarchant98 - 6 months ago
651 0

No description

Swift

First App

//
//  ViewController.swift
//  Question App
//
//  Created by Alex Marchant on 28/03/2017.
//  Copyright © 2017 Alex Marchant. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    var questions = ["What is the name of the continent that is located North of South America & East of Asia? A. Europe B. Africa C. North America D. Australia",
                     "Cat's, Dogs or Fish? A. Cat's B. Dog's C. Fish",
                     "Do you drive? A. Yes B. No",
                     "Do you even lift kid? A. No B. What is lifting? C. Na I crossfit D. Hell YEAH!",
                     "What are the names of my dogs? A. Bensone & Poppy B. John & Gill C. James & George D. Da Puss & Snoop Digdog",
                     "What gym do I go to? A. Buzz Gym B. A Gym C. David Lloyd D. The Gym"]
                     //"When was the first ever email sent?",
                     //"... What was that email about?"]
    
    var questionsAnswers = ["B", "B", "D", "A", "B", "A"]
    var currentQuestionIndex = 0
    var answer = "Null"
    
    func checkAnswer(answer: String)
    {
        if questionsAnswers[currentQuestionIndex] == answer
        {
            self.performSegue(withIdentifier: "correct", sender: nil)
            currentQuestionIndex += 1
        }
        else
        {
            self.performSegue(withIdentifier: "incorrect", sender: nil)
        }
    }
    
    
    @IBOutlet weak var questionLabel: UILabel!

    @IBAction func nextQuestionButton(_ sender: Any)
    {
        currentQuestionIndex += 1
        let numberOfQusetions = questions.count
        let nextQuestionIndex = currentQuestionIndex % numberOfQusetions
        
        questionLabel.text = questions[nextQuestionIndex]
    }

    //How will the buttons work:
    //Press the button, this will check the answer to the question
    //If the button pressed is correct, it displays 'Correct Label'
    //If the answer is incorrect, it displays 'Incorrect' and then returns them to the question
    //Once the cfhecking of buttons is completed, randomise the answers and check if the if the button input is correct?
    @IBAction func answerA(_ sender: Any)
    {
        answer = "A"
        checkAnswer(answer: answer)
    }
    @IBAction func answerB(_ sender: Any)
    {
        answer = "B"
        checkAnswer(answer: answer)
    }
    @IBAction func answerC(_ sender: Any)
    {
        answer = "C"
        checkAnswer(answer: answer)
    }
    @IBAction func answerD(_ sender: Any)
    {
        answer = "D"
        checkAnswer(answer: answer)
    }
    
}