Problems Unit 5 Hackathon High Score Sample App

Hi everyone. I would like to discuss this sample because I really think it is not the best one to be used as a guide and/or to share with the students.

The idea of the program is to look for the minimum and maximum values on different categories in order to display the corresponding cereal brand on the user interface.

The problem is that, for some categories, there are several cereal brands meeting the conditions. Ex: both Cheerios and Special K have the most proteins with a value of 6 grams. Another example: Cinnamon Toast Crunch, Cracklin’ Oat Bran, and Great Grains Pecan all have the maximum fat value with 3 grams. There are also similar cases for the minimum values.

When traversing the category list, we get the first of the maximum or minimum values and only display one brand name on the screen. This is wrong.

I modified the sample code by adding an extra loop. I would like to know what you think. I also would like to know if there is a better solution. This is what I did with the findMost function. I used a similar code for the findLeast function.

New findMost function:

function findMost() {
var input = getText(“mostDropdown”);
var category = getColumn(“Cereal Nutrition”, input);
var filteredMaxNames = ;
var max = 0;
var mostName;
for(var i = 0; i < category.length; i++){
if(category[i] > max) {
max = category[i];
for (var j = 0; j < category.length; j++) {
if (max == category [j] ) {
mostName = names[j];
setText(“mostOutput”, ((“The cereal/s with the most " + input) + " is/are “) + filteredMaxNames.join(”\n”));


A few more things: when remixing the app you need to import the Cereal Nutrition Table again, but you also have to change the names of the categories in the design tab, since they are different from the ones used in the sample.

Also, you will have to be especially careful with the protein column named: Grams of Protein. The column name has an extra space between the words “of” and “Protein”. You either need to edit the name in the table or add an extra space in the name in the dropdown menu. If not, you will see an error message in the console.

1 Like

Thanks for pointing this out. I will pass on this info to the staff. I like your solution that finds a list of all cereals that fit the criteria.

In the future, if you find any other mistakes please let know.

1 Like

Hi there. Sorry, but there is something else.

When the students select a category from the dropdown menu and, after that, they select Pick a Category, they get an error message. The message says: "You tried to get a column called “Pick a Category” from a table called “Cereal Nutrition”, but that column doesn’t exist. "

To solve this other issue, I added another if statement. See the screenshot.

Thank you,

1 Like

I noticed this too about the error message saying this column does not exist. For me it was the sodium column. The table says Grams of Sodium.

1 Like

Yes. I think the names of the columns in the table changed from last year to this year. So, if you want to remix the app, you not only need to import the table again, but you need change the names listed in the dropdown menu.

But again, if you select a category (any one) and then you click in “select a category” you will get an error message, unless you somehow fix the code. I added the else - if statement shown in the screenshot to solve it.

Besides this, there is something else that I would fix. If you select a category in the findMost or findLeast screens, go back to the home screen and then back again to the findMost or findLeast screens, the mostOutput or leastOutput are not cleared. Here you have another screenshot of what I did to solve this.

Alejandra R

1 Like