I want to create a simple calculator for a simple challenge I found on the internet which calculates the tip you leave for a bill depending on what the value of that bill is, if its between 50 and 300 the tip percentage should be 20%, otherwise it should be 15%.
I want to change the current value of X with the new value inside my If statement once the conditions have been met but after I run the code the initial value is taken.
I’ve tried to define X inside the IF statement but still not working.
Can somebody help me with a hint to what I’m doing wrong so I can fix it by myself?
Thank you!
let bill = 300;
let x = 0;
let percentage = x;
let tip = (percentage / 100) * bill;
if (bill >= 50 && bill <= 300) {
x = 20;
else {
x = 15;
and I’ve tried it like this:
let bill = 300;
let percentage = x;
let tip = (percentage / 100) * bill;
if (bill >= 50 && bill <= 300) {
let x = 20;
else {
let x = 15;
Alexandru Baginean is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.