Two dimensional array and Data Tables

Link to the project or level: N/A - This is a separate project.

What I expect to happen:
This is a prototype of a Study Hall Helper app that allows students to indicate when they are done with which homework and if they are willing to help others. Multiple students are running copies of the app at the same time, and reading and writing to the data table regularly to see each other’s changes. I store the dones (T/F if the homework is done, [studentID][subjectID]) and helps (T/F if indicated they can help others [studentID][subjectID]).

What actually happens:
It is working for the first student, at index 0, but not the second student, at index 1. The dones two-dimensional array seems to have a list for the first dones[0] and a count for the second, dones[1], so when the record saves, six “undefined” save instead of six true or false.
dones But, I don’t know if this is because App Lab’s watcher window can’t handle 2D arrays.

What I’ve tried: [replace with a detailed description of what you’ve already tried to do to solve the problem]
Since two-dimensional arrays aren’t built into App Lab, I’m not sure if I have all the right syntax.

Here is a share link.App Lab - Code.org

I have an export zip file, since the app uses data tables, but I don’t see how to upload it.

Carol

I assume you are coming from a non-javascript background. In javascript, an array can have two different value types together.

On line 19 var dones you declared an array with a length of 2, the first element being [0,1] (an array of numbers), and the second being a 6 (a number).
You can see in the image below that dones is an array of numbers and arrays of numbers
Screen Shot 2022-01-07 at 3.47.48 AM

I won’t comment on why it is not a good idea to hard code students but the proper way to initialize dones was to do.

var dones = [[false, false, false, false, false, false], [false, false, false, false, false, false]]

… and another Array of 6 x false for each new student.

Incidentally, having a two dimensional array of dones and an identical two dimensional array of helps is also bad code from a semantic standpoint. You should instead have an array of students, who each have an array of subjects, who each have an object {done, help} ex: students[0][5].help

You can improve this even more by making the subject one of three values. It is unlikely that a person done with homework would also need help. So having 0 be help: false, done: false, 1 be help: true, done: false, and 2 be help:false, done:true would eliminate the need for an object. If you do need them to be separate however, consider using a bitfield.

Storing it in a table could also change. It seems you had an entry for each studentid and subjectid to circumvent csv not being able to store arrays and objects. You can try serializing JSON.stringify() and deserializing JSON.parse() in order to not have to create a new entry for each subject.

Thanks for all the info!
I started the app with items in the toolbox, now I keep adding new things. This helps a ton. I might move all the way to real objects and JSON, that’s the real answer.
THANK YOU!!!
Carol Ramsey