I used a case statement and the output is printing with no errors. Yet i am not being marked as correct. Any idea why?
const tipCalculator = (quality, totalBill) => {
var tip;
switch (quality) {
case ‘bad’:
tip = Math.round(totalBill * 0.05); // 5% tip
return tip ;
break;
case ‘ok’:
tip = Math.round(totalBill * 0.15); // 15% tip
return tip;
break;
case ‘good’:
tip = Math.round(totalBill * 0.2); // 20% tip
return tip;
break;
case ‘excellent’:
tip = Math.round(totalBill*0.3); // 30% tip
return tip;
break
default:
tip = Math.round(totalBill*0.18); // 18% tip
return tip;
break;
Hello, @danielzivharel523032. Welcome to the forum. There’s a few things we’ll need in order to give you some assistance. A link to the exercise would be very helpful. A description of the specific error or problem you are having will also help. Additionally, if you could post your entire code for the exercise using the </> button as described below that will also help. Thanks!
Press Enter to go to a blank line, click that icon, and you will see this:
Is this correct or wrong?
const tipCalculator = (quality, total) => {
switch(quality){
case ‘bad’:
let bad = (5/total)*total;
return bad + ‘%’;
break;
case ‘ok’:
let ok = (15/total)*total;
return ok + ‘%’;
break;
case ‘good’:
let good = (20/total)*total;
return good + ‘%’;
break;
case ‘excellent’:
let excellent = (30/total)*total;
return excellent + ‘%’;
break;
default:
let d = (18/total)*total;
return d + ‘%’;
break;
};
I’m working on the tip calculator project and not sure why my code is not accepted. I have run the code and all of the percentages are showing up correctly. Any advice is much appreciated!
ERROR MESSAGE: If ‘bad’ is entered, the function should return 5% of the total passed in