I would like to have my students complete a practice create task by making a vending machine app. After they complete their own, I would like to show them an example that meets all of the requirements.
I would create a function purchaseItem (index) to remove redundant code from the onEvents().
I would get rid of the summation variables. (e.g. currentCost) Just use the functions instead.
Create a constant var NOTENOUGH = "Not Enough!"; to represent the not enough money condition. If you use the constant as in changeDue = NOTENOUGH;. And then use that constant for comparison changeDue != NOTENOUGH. It becomes more clear what it is you are doing.
wow thank you so much for this advice. i really appreciate it!
i have a follow up question if you don’t mind.
do you see a problem with the way i have my calculateTotal function written? i understand that yours is more efficient, but for the create task the procedure chosen needs selection and iteration.