# Program for Create Task Suggestions

**URL:** <https://forum.code.org/t/program-for-create-task-suggestions/37504>\
**Category:** CS Principles\
**Tags:** create-task\
**Created:** [January 19, 2023, 6:38pm UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504 "2023-01-19T18:38:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mckiernk](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@mckiernk](https://forum.code.org/u/mckiernk)\
**Post date:** [January 19, 2023, 6:38pm UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/1 "2023-01-19T18:38:06Z")

</div>

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 - Code.org](https://studio.code.org/projects/applab/axxe9oDqGRb4mMwZ2NKPj7lrtnQdK74hFKrElup5kik)

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

Thank you in advance!!

---

<div class="post-metadata">

**Author:** ![varrience](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/varrience/32/8042_2.png) [@varrience](https://forum.code.org/u/varrience)\
**Post date:** [January 20, 2023, 10:47am UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/2 "2023-01-20T10:47:17Z")

</div>

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  
Here: [https://studio.code.org/projects/applab/oTq2F81\_Oy\_05G2xVEgXetyJAjM1SzG4mP5UEzcP-Zs/view](https://studio.code.org/projects/applab/oTq2F81_Oy_05G2xVEgXetyJAjM1SzG4mP5UEzcP-Zs/view)

I hope this turns out to be useful as reference material

Best, Varrience

---

<div class="post-metadata">

**Author:** ![mckiernk](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@mckiernk](https://forum.code.org/u/mckiernk)\
**Post date:** [January 20, 2023, 1:58pm UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/3 "2023-01-20T13:58:22Z")

</div>

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?

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/3/32438206b4db1cfdfee99e2824c74f61d66d050a.png)

---

<div class="post-metadata">

**Author:** ![letti42](https://avatars.discourse-cdn.com/v4/letter/l/7ea924/32.png) [@letti42](https://forum.code.org/u/letti42)\
**Post date:** [January 20, 2023, 3:46pm UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/4 "2023-01-20T15:46:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [January 20, 2023, 8:12pm UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/5 "2023-01-20T20:12:44Z")

</div>

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.

> **[Check out what I made](https://studio.code.org/projects/applab/0uysXJNJ90SHYoDMffp-c8ftHSch6nA31npa-VWu-0E)**
>
> I wrote the code myself with Code.org

---

<div class="post-metadata">

**Author:** ![mckiernk](https://avatars.discourse-cdn.com/v4/letter/m/dfb087/32.png) [@mckiernk](https://forum.code.org/u/mckiernk)\
**Post date:** [January 23, 2023, 2:00pm UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/6 "2023-01-23T14:00:57Z")

</div>

wow thank you so much for this advice. i really appreciate it!

i have a follow up question if you don’t mind.

> **[Check out what I made](https://studio.code.org/projects/applab/xN1gWStlShBDQVyWXE_AXnBm2QeSU8hU3AC21XptK8M)**
>
> I wrote the code myself with Code.org

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.

 ![image](https://us1.discourse-cdn.com/flex016/uploads/codeorgforum/original/2X/8/88cfb231b53aad095c6a59849ac1b4aa9a300917.png)

thanks again for your help 🙂

---

<div class="post-metadata">

**Author:** ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)\
**Post date:** [January 24, 2023, 2:20am UTC](https://forum.code.org/t/program-for-create-task-suggestions/37504/7 "2023-01-24T02:20:39Z")

</div>

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.
