Functions within Functions, unsure of how to continue doing this

Hi, first time posting. Trying to get a function working and I’m completely lost in how all the rules go together.
After searching online, I figured instead of typing it, I would get the code bit to do it all for me, while practicing other things.

However, as you can see after perhaps running it yourself, it doesn’t work.
I believe this is due to me not knowing how functions within functions work, and I’m not sure how I could call for an update to the randTopping and randCrust that I defined to be updated with the call of giveRandTopping and giveRandCrust.

If you could tell me how I could do this, or how the rules of javascript work?
I know there might be a way to have the functions called within functions, but something tells me I’m missing one single part that I just don’t know yet.

Thanks, sorry if you can’t understand what I’m trying to do. Please ask if you believe it would help clarify.

function takeOrder(topping, crustType) {
  console.log('Order:' + crustType + 'pizza topped with ' + topping);

//takeOrder('bacon', 'thin crust');

crustTypes = ['thin crust', 'thick crust', 'cheese crust', 'normal crust']
toppingTypes = ['pineapple', 'bacon', 'black olives', 'pepperoni'];

function giveRandCrust() {
var randCrust = crustTypes[Math.floor(Math.random() * crustTypes.length)]; }

function giveRandTopping() {
var randTopping = toppingTypes[Math.floor(Math.random() * toppingTypes.length)]; }

function takeNumOrders(iteration) {
  for (it = 0; it < iteration; it++) {
    takeOrder(randTopping, randCrust);


Change that to return.


takeOrder(giveRandTopping(), giveRandCrust());

Thanks so much! I know it might be pretty simple… Really simple seeing your reaction, but it’s quite helpful.

It properly outputted, but it seems CodeCademy doesn’t want my custom made output, so I’ll do it manually, but it’s very satisfying to get it right…

Order: cheese crust pizza topped with bacon
Order: normal crust pizza topped with black olives
Order: thin crust pizza topped with pineapple

So cool!


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.