I'm new to the JS language and I don't know how to do something. I have a table such as:
<table id="table">
<thead>
<tr>
<td>Day</td>
<td>Student Name</td>
<td>Student Food Credit Used</td>
<td>Student Food Credit</td>
</tr>
</thead>
<tbody>
</tbody>
</table>
Above this table I have a button, "Add row". Everyday this table needs to be updated with the students food credit values. The column "Student Food credit Left" is a helper column, which serves just to help the user see how much credit the student has. For example: A student always starts with a credit of 100. So, in the Food credit left it should appear at first 100. Then if the student buys something then this value should be updated.
This row should be updated multiple times a day. For every purchage the student makes it's a new row that needs to be added and the credit left column should be updated with the one above it.
Date | Student Name | Credit Left | Credit Used
2022-09-01 | Harry | 100 | 50
Then when adding a new row, in the same day:
Date | Student Name | Credit Left | Credit Used
2022-09-01 | Harry | 50 | 10
It's important to mention that, this table of rows have multiple students. If the table is saved to the database before inserting a new row in the same day, I'm able to see how many credit left the student has. However, if I just keep adding rows, in the same day, before adding to DB, I'm not able to keep updating the credit with javascript.
EDIT
I followed the advice of the comment that I marked as the answer. So, I looped through all the rows in my table to see if I found a match to the value I wanted. If so, I put it in an array. Then I looped through this array to find the smallest number and kept updating it everytime I added a new row