Js: It is a program to make a kind of bill

Viewed 18

A shop will give discount of 10% if the cost of purchased quantity is more than 1000.

Ask the user for the quantity. Suppose, one unit will cost 100.

Judge and print total cost for user. Ask for name phone number as well as bill amount

const bill_maker = () => {
  const bill_format = {
    name_customer: prompt("Enter the customer's name"),
    phone_number: Number(prompt("Enter the customer's phone number")),
    total_bill_amount: Number(prompt("Enter the bill amount"))
  }
  
  // Conditions 
  if (bill_format.total_bill_amount > 1000) {
    return (`${bill_format.total_bill_amount}.Oh! You have 10% discount so you have to pay:` (bill_format.total_bill_amount / 1000) * 100)
  } else {
    return `${bill_format.total_bill_amount}. You have to pay`
    `${bill_format.name_customer} Do visit us again!`
  }
}

console.log(bill_maker())

1 Answers

The issue is because your template literal syntax is invalid. In each case you've split them without declaring new variables for the second part.

To fix the problem, merges the template literals in both sides of your if condition:

const bill_maker = () => {
  const bill_format = {
    name_customer: prompt("Enter the customer's name"),
    phone_number: Number(prompt("Enter the customer's phone number")),
    total_bill_amount: Number(prompt("Enter the bill amount"))
  }
  
  console.log(bill_format.total_bill_amount);
  
  // Conditions 
  if (bill_format.total_bill_amount > 1000) {
    return `${bill_format.total_bill_amount}.Oh! You have 10% discount so you have to pay: ${(bill_format.total_bill_amount / 1000) * 100}`;
  } else {
    return `${bill_format.total_bill_amount}. You have to pay: ${bill_format.name_customer}. Do visit us again!`
  }
}

console.log(bill_maker())

Related