Prompt #1

Student-developed procedure with a parameter, sequencing, selection, and iteration

snippet1 Explanation:

  • Procedure named submitPoll with a parameter (formId)
  • Contains sequencing because it goes through the process of getting question label, getting user input, transforming the string, fetching user data, and finally submitting the poll.
  • Uses selection for error handling using if (!userResponse.ok)
  • Uses iteration when transforming the string to cycle to the next poll form

Prompt #2

Call to above procedure

snippet2 Explanation:

  • Shows where submitPoll is called using pollForm1
  • Passes the relevant form ID to the procedure so it can handle user input for that specific poll form
  • Uses HTML onsubmit event that triggers the function and

Prompt #3

Storing data in a list

snippet3 Explanation:

  • Shows storing data into groupedPolls, which is a list that maps each user name to an array of polls
  • Uses data.forEach to iterate through each poll item and pushes (aka. appends) to the -1 element of the array
  • Makes data management simple by storing related poll results under one key

Prompt #4

Using the same list

snippet4 Explanation:

  • Uses the data in groupedPolls to generate viewable table rows
  • Accesses each list using Object.entries(groupedPolls).forEach(...) and iterates through each item using a for loop (polls.forEach(...))
  • Inserts <input> and <button> HTML elements based on the poll data of each user
  • Adds interactivity to page