Menu
Coddy logo textTech

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 icon

Challenge

Beginner

To kick off, write the data setup code:

  1. Initialize an empty array of questions ([(String, String, String)])
  2. Print the count
  3. Print whether the array is empty

The expected output is:

0
true

Cheat 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 elements

Try it yourself

// TODO: declare an empty [(String, String, String)] called questions,
// then print count and isEmpty
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Logic & Flow