Project Overview
Part of the Logic & Flow section of Coddy's Swift journey — lesson 49 of 56.
The second project is a quiz engine. State is a list of questions, each a tuple of (category, text, answer):
var questions: [(String, String, String)] = [
("math", "2 + 2?", "4"),
("geo", "Capital of France?", "paris")
]Across the next four lessons you'll add features one at a time:
- Add questions and ask them in order
- Score answers (case-insensitive, trimmed)
- Filter by category
- Summarise the run with a per-category breakdown
Like the Habit Tracker, each lesson stands alone, you'll re-build the question bank at the top of every file.
Challenge
BeginnerTo kick off, write the data setup code:
- Initialize an empty array of questions (
[(String, String, String)]) - Print the count
- Print whether the array is empty
The expected output is:
0
trueCheat sheet
A quiz engine stores questions as a list of tuples with (category, text, answer):
var questions: [(String, String, String)] = [
("math", "2 + 2?", "4"),
("geo", "Capital of France?", "paris")
]Useful array properties:
questions.count // number of elements
questions.isEmpty // true if no elementsTry it yourself
// TODO: declare an empty [(String, String, String)] called questions,
// then print count and isEmpty
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Logic & Flow
1Strings In Depth
Count and IndicesCase and TrimSearching in StringsSplitting and JoiningReplacing SubstringsRecap - Username Check