Math calculations

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. Let’s return to QVR Tours for this thread and write someJavaScript 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 traveler’s first and last name

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

Can be very basic

examples

const discount=150;

var totalCost = 0;

const tourCost= 2500;

const tourCost2=3500;

const conciergeFee1=150;

const conciergeFee2=300;;

const ticketAfterDiscount =0;

var firstName = prompt (“Enter first name”);
var lastName= prompt (“Enter Last name”);

var tourPrice = (“Enter the amount of the ticket”);

if (tourPrice < tourCost && tourPrice < tourCost2);

{

tourPrice = totalCost;

cosole.log(“Total Cost = $” tourPrice);

}

else if (tourPrice > tourCost && tourPrice < tourCost2);

{

tourPrice = totalCost + conciergeFee1;

cosole.log(“Total Cost = $” tourPrice);

}

else if (tourPrice > tourCost && tourPrice > tourCost2);

{

tourPrice = totalCost + conciergeFee2;

cosole.log(“Total Cost = $” tourPrice);

}

else

{

cosole.log(“Invalid Entry”);

}

var personsInGroup = (“Enter number of people in group”);

if (personsInGroup > 8)

{

ticketAfterDiscount = totalCost + discount;

cosole.log(“Total Cost = $” ticketAfterDiscount);

}

else

{

ticketAfterDiscount = totalCost;

cosole.log(“Price after discount = $” ticketAfterDiscount);

}

Var nameOfGuest = firstName+ lastName;
console.log(“ Thank you” nameOfGuest “your total cost is $” ticketAfterDiscount);