From c3ac1c94682d105371f0d36d782c5b1788aed0df Mon Sep 17 00:00:00 2001 From: Jalaj <83359199+Jalaj2002@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:00:24 +0530 Subject: [PATCH 1/4] Create Model --- Quizzler-iOS13/Model | 1 + 1 file changed, 1 insertion(+) create mode 100644 Quizzler-iOS13/Model diff --git a/Quizzler-iOS13/Model b/Quizzler-iOS13/Model new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/Quizzler-iOS13/Model @@ -0,0 +1 @@ + From bcb76ff06597216e14cd374bdcffd722f7a641e4 Mon Sep 17 00:00:00 2001 From: Jalaj <83359199+Jalaj2002@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:00:58 +0530 Subject: [PATCH 2/4] Delete Model --- Quizzler-iOS13/Model | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Quizzler-iOS13/Model diff --git a/Quizzler-iOS13/Model b/Quizzler-iOS13/Model deleted file mode 100644 index 8b137891..00000000 --- a/Quizzler-iOS13/Model +++ /dev/null @@ -1 +0,0 @@ - From 20025fa8c73b17cb97a16cfbec920ea626ba0c7b Mon Sep 17 00:00:00 2001 From: Jalaj <83359199+Jalaj2002@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:19:31 +0530 Subject: [PATCH 3/4] Delete ViewController.swift --- Quizzler-iOS13/ViewController.swift | 20 -------------------- 1 file changed, 20 deletions(-) delete mode 100644 Quizzler-iOS13/ViewController.swift diff --git a/Quizzler-iOS13/ViewController.swift b/Quizzler-iOS13/ViewController.swift deleted file mode 100644 index 39ffb5fc..00000000 --- a/Quizzler-iOS13/ViewController.swift +++ /dev/null @@ -1,20 +0,0 @@ -// -// 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 { - - override func viewDidLoad() { - super.viewDidLoad() - // Do any additional setup after loading the view. - } - - -} - From fb6c5b6b7ff7991e9b7f1c86aeaf9845c64f830f Mon Sep 17 00:00:00 2001 From: Jalaj <83359199+Jalaj2002@users.noreply.github.com> Date: Fri, 6 Jan 2023 01:21:43 +0530 Subject: [PATCH 4/4] Add files via upload --- .../Controller/ViewController.swift | 58 ++++++++++ Quizzler-iOS13/Model/Question.swift | 17 +++ Quizzler-iOS13/Model/QuizBrain.swift | 61 ++++++++++ .../View/Base.lproj/Main.storyboard | 109 ++++++++++++++++++ 4 files changed, 245 insertions(+) create mode 100644 Quizzler-iOS13/Controller/ViewController.swift create mode 100644 Quizzler-iOS13/Model/Question.swift create mode 100644 Quizzler-iOS13/Model/QuizBrain.swift create mode 100644 Quizzler-iOS13/View/Base.lproj/Main.storyboard diff --git a/Quizzler-iOS13/Controller/ViewController.swift b/Quizzler-iOS13/Controller/ViewController.swift new file mode 100644 index 00000000..f69cbfc3 --- /dev/null +++ b/Quizzler-iOS13/Controller/ViewController.swift @@ -0,0 +1,58 @@ +// +// 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 scoreLabel: UILabel! + @IBOutlet weak var questionLabel: UILabel! + + @IBOutlet weak var falseButton: UIButton! + @IBOutlet weak var trueButton: UIButton! + + @IBOutlet weak var progressbar: UIProgressView! + + + + var quizBrain=QuizBrain() + + override func viewDidLoad() { + super.viewDidLoad() + updateUI() + // Do any additional setup after loading the view. + } + + @IBAction func answerButtonPressed(_ sender: Any) { + + let userAnswer=(sender as AnyObject).currentTitle! ?? "0" + let userGotItRight=quizBrain.checkAnswer(userAnswer) //Using the property of QuizBrain method and userAnswer is a internal parameter name + + + if userGotItRight{ + trueButton.backgroundColor=UIColor.green + } + else{ + falseButton.backgroundColor=UIColor.red + } + quizBrain.nextQuestion() + + Timer.scheduledTimer(timeInterval: 0.2, target: self, selector:#selector(updateUI), userInfo: nil, repeats: false) + + } + @objc func updateUI(){ + questionLabel.text=quizBrain.getQuestionText() + progressbar.progress=quizBrain.getProgress() + scoreLabel.text="Score: \(quizBrain.getScore())" + trueButton.backgroundColor=UIColor.clear + falseButton.backgroundColor=UIColor.clear + + } + + +} + diff --git a/Quizzler-iOS13/Model/Question.swift b/Quizzler-iOS13/Model/Question.swift new file mode 100644 index 00000000..590aa548 --- /dev/null +++ b/Quizzler-iOS13/Model/Question.swift @@ -0,0 +1,17 @@ +// +// Question.swift +// Quizzler-iOS13 +// +// Created by Jalaj's Macbook on 27/09/22. +// Copyright © 2022 The App Brewery. All rights reserved. +// + +import Foundation +struct Question{ + let text:String + let answer:String + init(q:String,a:String){ + text=q + answer=a + } +} diff --git a/Quizzler-iOS13/Model/QuizBrain.swift b/Quizzler-iOS13/Model/QuizBrain.swift new file mode 100644 index 00000000..e1145c3c --- /dev/null +++ b/Quizzler-iOS13/Model/QuizBrain.swift @@ -0,0 +1,61 @@ +// +// QuizBrain.swift +// Quizzler-iOS13 +// +// Created by Jalaj's Macbook on 27/09/22. +// Copyright © 2022 The App Brewery. All rights reserved. +// + +import Foundation +struct QuizBrain{ + let quiz=[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 + var score=0 + mutating func checkAnswer(_ userAnswer:String) -> Bool{ + if userAnswer==quiz[questionNumber].answer{ + score+=1 + return true + //Got it right + } + else{ + return false + //User got it wrong + } + } + func getQuestionText()->String{ + return quiz[questionNumber].text + + } + + + func getProgress()->Float{ + return Float(questionNumber+1)/Float(quiz.count) + } + mutating func nextQuestion(){ + if questionNumber+1Int{ + return score + } +} diff --git a/Quizzler-iOS13/View/Base.lproj/Main.storyboard b/Quizzler-iOS13/View/Base.lproj/Main.storyboard new file mode 100644 index 00000000..07d3b46c --- /dev/null +++ b/Quizzler-iOS13/View/Base.lproj/Main.storyboard @@ -0,0 +1,109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +