Question: JavaScript JavaScript can add another dimension to our sites with simple math calculations, such as working with conditionals for an order form to add the

JavaScript

JavaScript can add another dimension to our sites with simple math calculations, such as working with conditionals for an order form to add the proper taxes or currency conversions. Imagine a generic tour website. Lets write some JavaScript that will assist in the following calculations:

  • Add a concierge fee of $150 to tours that cost more than $2,500 and a fee of $300 if a tour costs more than $3,500
  • Concatenate a travelers first and last name

Also, Discounts a tour if there are more than 8 people attending (you decide on the discount amount)

Add comments describing what your functions do.

The answer may vary, but in general, it may include your proposed html file including your JavaScript file (myname.js) included in the html file. The sample syntax to include your JavaScript file is shown below:

*** The sample syntax to include your JavaScript file is shown below: ***

Continue with writing the JavaScript as below sample framework:

Define your variables - including cost variable

Add your function (s)

Calculate Cost (cost will be (tour price (tprice) + concierge fee of $150 $300) discount amount (discount))

Hint: To calculate cost your logic will include checking for: (assuming, totalcost is variable for total cost, tprice is the variable for tour price, passnum is number of passengers in attending the tour, discount is discount either as rate or amount (any rate or amount, you decide it, assume discount is deducted from tour price + concierge fee of $150 $300)):

Therefore, first calculate (tour price + concierge fee of $150 $300), then calculate discount based on number of passengers, then calculate the cost.

As an example:

(tour price + concierge fee of $150 $300) can be as below - SAMPLE Cost calculation LOGIC part only, NOT the complete code. You need to have the complete code: defining variables, adding functions and etc.

sample....

if (tprice < 2500) {

tprice = tprice + 0;

}

else if (tprice >= 2500 && tprice < 3500) {

tprice = tprice + 150;

}

else if (tprice >= 3500) {

tprice = tprice + 300;

}

discount is as below, first need to declare either discount rate or amount of your choice, then calculate it.

if (passnum >= 8) {

totalcost = tprice - (tprice * discount); OR totalcost = tprice (discount amount)

}

else if (passnum < 8) {

totalcost = tprice

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!