0
function abc(){
    console.log("Delieverd food order: ",orderNumber);
}

function placeOrder(orderNumber){
    console.log("Customer: ", orderNumber);
    cookAndDeliverFood(abc);
}

fucntion cookAndDeliverFood(callback){
    setTimeout(callback,5000);
}

//Simulate users webrequests

placeOrder(1);

placeOrder(2);

placeOrder(3);

placeOrder(4);

placeOrder(5);

This is giving me syntax error. Can anyone explain the reason?

6
  • 1
    fucntion !== function Commented Apr 5, 2017 at 5:02
  • orderNumber is not in scope in abc. It will be undefined. Commented Apr 5, 2017 at 5:02
  • console.log("Customer: ", orderNumber); have comma in it. Please replace it with plus (+). Commented Apr 5, 2017 at 5:03
  • 1
    @Shubham console.log prints all of its parameters as space-separated strings, so alternatively they could just remove the space after the colon. Commented Apr 5, 2017 at 5:05
  • fucntion cookAndDeliverFood() should be function cookAndDeliverFood. it may be a typo. Commented Apr 5, 2017 at 5:05

1 Answer 1

3

Running your code, I get this error:

fucntion cookAndDeliverFood(callback)
         ^^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected identifier

You have misspelled the keyword function.

That is not the only problem with the code. Function abc() tries to use the identifier orderNumber but, the way this code is written, orderNumber is out of scope there. But the misspelling of function is the immediate problem you are facing and the reason you are getting a SyntaxError.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.