3a

  • A.i - The point of this function / program is to give users the option to store their diets as well as give the diet a name by inputting all information they prefer depending on their goal by inputting macros and special notes of their diet.

  • Ii - This software enables users to enter information about their dietary habits, including details such as name, sugar content, calorie count, carbohydrate, fat, and protein levels, along with additional notes. Users begin by identifying the person to whom the diet belongs. Diets are stored in the database under the user’s name, making it easy to access previously saved information by simply typing in their name and loading the diet. Users can also switch between diets for a preview and delete them as needed.

  • Iii - To use the program, users enter their macro information, diet name, and additional notes into designated input fields. The program collects this data and provides feedback on whether the diet was successfully added, based on whether all required fields were filled out. Once added, the diet can be accessed by calling up the user’s name and viewing their saved entries.

3b

  • I - image
  • Ii - image
  • iii - The name of this variable is fields
  • Iv - The information within my list holds great importance for my program, as it encompasses all the distinct characteristics of each diet entry. This is crucial to the functioning of the program, as it enables the retrieval and storage of diet data, ultimately populating the tables for a given user’s saved diets upon loading.
  • V - If I don’t use the “fields” variable, my program will become inefficient and require a separate variable for each unique attribute. This would make my code unnecessarily long and complicated. So, by using the “fields” variable, I can streamline the code and make it more efficient.

3c

  • I - image
  • Ii - image
  • Iii - The “loadDiets” procedure is essential to the program. It retrieves the input value of a user ID element and uses it as a query parameter for a fetch request to a local server. The response, which is in JSON format, contains all the existing diets associated with the user input. This allows users to preview their diets by loading any saved diets and toggling through them. Without this function, users would not be able to view their saved diets and navigate through them.
  • Iv - The “addInventory” function in the code starts by collecting input data from the users and putting it into a dictionary to store for the user. It then checks if the appropriate fields of the diet are filled out using selection, and prompts the user to fill out all fields correctly if they are not. After that, the function calls the POST method. To handle any errors that may occur during the fetch request, the function uses iteration in the form of a try-catch block. Finally, the function uses fetch to send a POST request to a specified URL, logs the success response to the console, and displays an alert to the user.

    3d

  • I. - The user inputs a valid user ID, and the function fetches all the saved diets associated with that user ID. This call tests the condition of whether a valid user ID has been entered, and if it has, it will execute a sequence of code that retrieves all the saved diets of that user. The result of this call will be the successful loading of all saved diets associated with the user ID entered.
  • Ii - The user inputs an invalid user ID, and the function fails to fetch any saved diets. This call tests the condition of whether a valid user ID has been entered, and since it has not, the condition will cause a different segment of code to execute that displays an error message stating that the user ID entered is invalid. The result of this call will be an error message that indicates an invalid user ID was entered.
  • Iii - The “loadDiets” procedure is essential to the program as it enables users to view their saved diets and navigate through them. The procedure starts by retrieving the input value of a user ID element, which serves as a query parameter for a fetch request to a local server. The response from the server is in JSON format and contains all the existing diets associated with the user input. Once the response is received, the procedure parses the data and maps the data for each saved diet to the corresponding table rows in the user interface. This allows users to preview their diets by loading any saved diets and toggling through them. By using this procedure, users can easily access and view their saved diets, making it convenient for them to track their dietary habits over time.