Question 1

If you are linking a route function named home to a Button, which of the following would be correct ways of specifying the second argument?

Button("Home", ___)

Select every answer that applies, then check.

  • Correct. Every Button in the reading points at its route with a quoted string, e.g. Button("Increase", "index").
  • Correct. The reading says a route is passed "by name, not by call"; the bare function reference works too, exactly as the DrafterIssues question's own Button("Clear", clear_value) shows (no parentheses needed).
  • Not quite. Parentheses call home immediately, embedding whatever Page it returns right now, instead of deferring execution until the button is clicked.
  • Not quite. This still calls home immediately, for the same reason home() does; adding the state argument doesn't delay execution until a click.
  • Not quite. Route functions are not stored on the state; home is just a name in the surrounding program.

Question 2

In the program below, which of the following statements are true about when the home route function is executed/called?

from drafter import *

@route
def index(state: str) -> Page:
    return Page("Welcome!", Button("Next Page", "next_page"))

@route
def next_page(state: str) -> Page:
    return Page("This is the next page.", Button("Go Home", "home"))

@route
def home(state: str) -> Page:
    return Page("This is the home page.", "The end.")

start_server("")

Select every answer that applies, then check.

  • Not quite. Defining a route with @route only registers it; nothing calls home before start_server starts serving pages.
  • Correct. Every route function, home included, only runs once the server is up and a page is requested or a button is clicked.
  • Not quite. The first page loaded calls index, not home.
  • Not quite. That button's route is "next_page", so it calls next_page, not home.
  • Correct. That button's second argument is "home", so clicking it is exactly what calls the home function.
  • Not quite. next_page only builds a Button that names "home" as a route; it does not call home itself.

Question 3

In the Drafter program below, which names must match exactly for the program to work correctly?

from drafter import *

@route
def index(___: ___) -> Page:
    return Page(1, Div(
        TextBox(___),
        Button(___, ___)
    ))

@route
def about(___: ___, feedback: str) -> Page:
    return Page(2, "Thank you for your input!")

start_server(0)

Select every answer that applies, then check.

  • Not quite. Every example in the reading happens to name its entry route index, but nothing in the reading states that this exact name is required.
  • Not quite. The current state is always passed as the first parameter by position, not matched by name; only the parameters that a TextBox feeds need a specific name.
  • Not quite, for the same reason: the first parameter is always the current state by position, whatever it is named.
  • Not quite. This program's state is a number (Page(1, ...), start_server(0)), and other readings use int or str state just as validly.
  • Correct. The reading explains that a TextBox's name is matched to a parameter in the route it submits to; here that route is about, whose extra parameter is named feedback.
  • Not quite. Every TextBox in the reading takes a quoted string, e.g. TextBox("guess"), not a bare name.
  • Not quite. A button's label is just display text for the user; the reading uses "Increase", "Submit", "Try again" and others interchangeably.
  • Correct. The button needs to link to the about route, and Drafter accepts a route either as a quoted string or as the bare function name.

Question 4

Which of the following statements describe issues in the following code?

from drafter import *

@route
def index(state: int) -> str:
    return Page(state, Div(
        "Current number:",
        bold(state),
        TextBox("new_value"),
        Button("Set", "set_value"),
        Button("Clear", clear_value)
    ))

@route
def set_value(state: int, new_value: int) -> Page:
    return index(new_value)

@route
def clear_value(state: int) -> Page:
    return index(0)

start_server(7)

Select one answer, then check.

  • Correct. Every other example in the reading writes bold(str(state)); here bold(state) passes the raw integer instead.
  • Not quite. Drafter uses a route's parameter types to convert the text a TextBox submits, so typing this parameter int is exactly how you ask for a number back.
  • Not quite. Reusing index to build the next page is the pattern the "Multiple Routes" example itself uses (return index(state + 1)).
  • Not quite. Adding parentheses would call them immediately instead of passing their names to Button; the bare names are correct as written.
  • Not quite. The reading's own "Drafter State" and "Buttons" examples both call start_server(7).

Question 5

Which statement best describes how State works in Drafter applications?

Select one answer, then check.

  • Not quite. The reading calls state "a central part of any program", not something unique to Drafter.
  • Not quite. The reading says the opposite: "a central part of any program is the state", not just Drafter programs.
  • Correct. The reading states this directly: "Route functions take the current state as an argument and return a new state as part of the Page."
  • Not quite. None of the reading's examples use a global variable; the state is always a parameter and a returned value.
  • Not quite. No such function appears anywhere in the reading.
  • Not quite. The "Buttons" example computes a separate next_state value and returns it through Page; the original state parameter itself is never reassigned in place.