-1

const billCalculator = (price, tax = 0.13, tip) => {

    if (price <= 20 && price >= 1) {
      tip = 0.05;            

    } else if (price >= 21 && price <= 40) {
      tip = 0.15;
                        
    } else if (price >= 41 && price <= 60) {
      tip = 0.15;
                        
    } else if (price >= 61) {
      tip = 0.25;
                
    }  
  
    return price + (price * tax) + (price * tip);

  };

  const popup = prompt(`Your bill:`);      
 
  const call = billCalculator(popup);
  

  console.log(call);

Here I wanted whatever the amount I put in the prompt is the argument for Price. But the return not adding up. Say if I put 100, I am getting 1001325 but it should be 138. What I am doing wrong here actually?

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320

1 Answers1

0

prompt returns a string so it will be compared charcter-by-character when you use greater or less than.

You need to convert it into a number (e.g. with parseFloat).

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335