Check your understanding of the previous reading: the Commenter program.

Question 1

The page_commenter function displays the original text and any comments that have been added. Which of the following is TRUE about how the page_commenter function works?

Select one answer, then check.

  • Not quite. content starts as [Header("Code Commenter")], so its first element is a Header, not a Div.
  • Not quite. The first two append calls are in an if/else, so only one of them ever runs; combined with the separate if line.comment append, at most two elements are added per iteration, never three.
  • Not quite. The else branch for an empty line appends Div(classes="comment-line", style_height="1.5em"), a blank spacer with no button at all.
  • Correct. A blank line's spacer Div has zero content components, a comment's Div(small_font(line.comment), ...) has one, and a line with text has two: Div(line.original, Button(...), ...).

Question 2

Which of these is NOT an accurate description of how functions are decomposed in this program?

Select one answer, then check.

  • Accurate. start_commenting returns error_page(...) when there's no file and no text.
  • Accurate. Once the lines are parsed, it returns page_commenter(state).
  • Accurate. lines = parse_lines(text) is right there in the function body.
  • Accurate. save_comment ends with return page_commenter(state).
  • Correct, this is the false one. save_comment only does state.comments[index].comment = comment_box before calling page_commenter; it never calls parse_lines, which only runs once, from start_commenting.

Question 3

The start_commenting function updates the State to include the original_text field, which contains the original text to be commented on. Why is the original_text field kept in the State?

Select one answer, then check.

  • Not quite. page_commenter never reads state.original_text; it builds its display from state.comments, where each Line already carries its own original text.
  • Not quite, for the same reason: comments come from each Line.comment, not from state.original_text.
  • Not quite. There is no add_comment function in this program; comments are saved by save_comment, which doesn't use original_text either.
  • Not quite, for the same reason: there is no add_comment function here.
  • Correct. index pre-fills the text area with TextArea("text_box", state.original_text), so when the "Reset" button on the commenting page sends the user back to index, their earlier text reappears instead of an empty box.
  • Not quite. Uploading a file and pressing "Start" goes straight to page_commenter, not back to index, so index is never shown "immediately after" an upload.