Exercise 3: Place Order

Practice function implementation by solving the tasks given in this lesson.

Problem statement

In this exercise, you are required to complete the placeOrder() function to get the desired output.

Function description

The placeOrder() function assumes values for shipping and date if those values are not given. There are two requirements that the function needs to implement:

  • The default value of date should be today’s date.
  • If not given, shipping if not given, should be $5 if the amount passed is less than $20. Otherwise, it should be $10.

Task 1

In this task, you are required to get the desired output for the respective input calls.

Sample input and output

Function call Output
placeOrder(1, 12.10, 3, new Date('05/15/2018')); shipping charge for id: 1 is $3 Date:15
placeOrder(1, 25.20, 10); shipping charge for id: 1 is $10 Date: Today’s date
placeOrder(1, 12.05); shipping charge for id: 1 is $5 Date: Today’s date
placeOrder(1, 25.30); shipping charge for id: 1 is $10 Date: Today’s date
placeOrder(1, 25.20); shipping charge for id: 1 is $10 Date: Today’s date

Exercise

The code given below throws an error. Fix the parameter list so the function behaves as expected. The solution is given in the next lesson but it’ll be a better practice if you try to do this challenge yourself first.

Get hands-on with 1400+ tech skills courses.