[SOLVED] Js: It is a program to make a kind of bill

Issue

This Content is from Stack Overflow. Question asked by Pradyot Sinha

// A shop will give discount of 10 % if the cost of purchased quantity is more than 1000.Ask user for 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())



Solution

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())


This Question was asked in StackOverflow by Pradyot Sinha and Answered by Rory McCrossan It is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?