Program for Create Task Suggestions

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.

Here is what I have come up with so far: App Lab -

I would appreciate any suggestions on how to make sure this program meets the requirements of the task.

Thank you in advance!!

Salutations @mckiernk,

After a little tinkering i think i managed to get out a better example, not sure if it fulfills the target that you were looking for but I’ll link it anyways

I hope this turns out to be useful as reference material

Best, Varrience

1 Like

Thanks! This is great. I am just wondering why the lists itemsBought and itemsBoughtPrices are populated with 0’s as opposed to being empty lists?

The 0s are there because they increment in the project. If you try to add 1 to an undefined list index, it won’t work. undefined+=1 won’t work.


Personally, I would keep going the way you were.

  1. I would create a function purchaseItem (index) to remove redundant code from the onEvents().
  2. I would get rid of the summation variables. (e.g. currentCost) Just use the functions instead.
  3. 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.
1 Like

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.

thanks again for your help :slight_smile:

It doesn’t have to be efficient. But it does have to be a significant enough project.

One thing you could add is another list with how many of each item is in the machine. You will then have to test if the machine is empty of that item.