Learning the basics and had this exercise:
"Write a function addWithSurcharge that adds two amounts with surcharge. For each amount less than or equal to 10, the surcharge is 1. For each amount greater than 10, the surcharge is 2. The call addWithSurcharge(5, 15) should return 23."
I had put:
function addWithSurcharge(num1, num2) {
if (num1 <= 10) {
num1 += 1;
} else {
num1 += 2;
}
if (num2 <= 10) {
num2 += 1;
} else {
num2 += 2;
}
return num1 + num2;
}
Which works, but want to learn better syntax. Could something like
if (num1, num2 <= 10) {...
work? I realize can't do the || operator because it could affect the wrong num.