Created
August 8, 2019 11:54
-
-
Save angelabauer/f98016d22748b28d543b8f6b2b9e366b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Foundation | |
| struct QuizBrain { | |
| var questionNumber = 0 | |
| var score = 0 | |
| 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") | |
| ] | |
| func getQuestionText() -> String { | |
| return quiz[questionNumber].text | |
| } | |
| func getProgress() -> Float { | |
| return Float(questionNumber) / Float(quiz.count) | |
| } | |
| mutating func getScore() -> Int { | |
| return score | |
| } | |
| mutating func nextQuestion() { | |
| if questionNumber + 1 < quiz.count { | |
| questionNumber += 1 | |
| } else { | |
| questionNumber = 0 | |
| } | |
| } | |
| mutating func checkAnswer(userAnswer: String) -> Bool { | |
| if userAnswer == quiz[questionNumber].answer { | |
| score += 1 | |
| return true | |
| } else { | |
| return false | |
| } | |
| } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment