Overview

My feature is essentially a calorie counter with two parts to it.

The first is a calorie counter that needs user data to output the amount of calories burned in a day.

The second is a feature that inputs a food and its calories to make a list of foods, and can calculate the total amount of calories consumed. It will also warn the user when they are close to going over their calorie limit.

The value that will be stored in their user account is the max calorie count for that user.

Video Response

Purpose:

  1. The purpose of the overall feature is to solve the problem of an unhealthy lifestyle by calculating daily calorie intake and managing it.
  2. For the first part, using a formula for metabolic rate, depending on the gender, the program will use the user's age, sex, weight, height, and activity level and produce the output of the user's maximum calories, letting the user have the option to save this value to their account. For the second part, the program will use the inputs of food name and calorie amount and output a table showing the summative foods put through the day.

  3. For the first part, the input is the integers sex, age, weight, height, and the multiple-choice activity level (later stored as an integer) of the user. The output is the maximum calories the user can consume daily. For the second part, the input is the name of a food being consumed, and the amount of calories in it. The output is a table showing every food entered in that day, as well as the calories of them all.

Data Abstraction

  1. The table created acts as a list for both frontend and backend. Food name and calorie amount variables are stored in said table. The sum of the calorie amounts is used to calculate whether or not the user should stop calorie consumption for the day, as shown in the code below.

  2. The list is the table creation and adding of rows itself, as shown in the code below.

  3. The data of the food's name is simply for the user to identify where each calorie amount comes from, but the calorie amounts are added together to check if the user is going over their daily maximum calorie consumption, as shown in the code below.

If this were not here, the user could not keep track of their daily calorie consumption, meaning that the feature establishes the maximum calorie consumption for the user, but does not help manage the user's consumption to fit said max calories. The only other way to achieve such a management section would be to create variables for every possible entry, which would be inefficient and a waste of data.

Managing Complexity

  1. There are functions to fetch a JSON list from a user database. The name of the database is the URL inputted into the fetch() method. The program will save the age, gender, weight, height, activity amount, and maximum calorie amount of the user in said database, as shown in the code below:
  1. If this list would not be used, then data would not be saved to the user's account, and the inputs will have to be repeatedly be inputted each time the user loads the website rather than just a login system, which is inefficient.

Procedural Abstraction

  1. Below is the procedure that calculates the maximum calories that a user can consume in one day:
  1. This procedure is called in the front end of the feature, as shown in the code below:
  1. This function makes one half of the first part of the feature. This takes in the user's input and returns a value that is later stored in the user's account in the backend database, contributing to the establishment of the user's maximum calories - the overall functionality of the feature.

Algorithm Implementation

The functions below respectfully calculate the maximum calorie amount a user can consume daily and save that value to the user's account in a backend database:

In the function "calculateMaximumCalories()" I started by grabbing the values of sex, age, weight, height, and activity level from the inputs from the frontend, using the built-in "getElementById()" function. Since the formula for calculating maximum calories differs according to sex, I use conditional statements to check if the user's sex is female or male. The selected condition will then run the appropriate formula. I then grab the place in the frontend where I want to display the maximum daily calorie intake of the user. Before displaying the result using ".innerHTML" I first "console.log()" each value for debugging purposes. Then I display the maximum daily calorie intake along with some helpful text for the user.

Testing

  1. For the testing, I will select the procedure of the food table. Below is the code for that:

The first call is of when the user has eaten an apple:

The second call is of when the user has eaten a banana:

  1. I can use my own age, height, weight, gender, and activeness to find my max amount of calories and test if the app is making me healthier.

  2. The results of each call are shown in the images above.