Hey there, I'm currently developing an app that simulates pricing. Below is a snippet of the code I am working on:
function calculatePrice(x) {
if (x >= '1' && x <= '50') {
var sum = (120 * x);
hasil.value = 'Rp.' + parseFloat(sum * 1000);
} else if (x >= '51' && x <= '100') {
var sum = (115 * x);
hasil.value = 'Rp.' + parseFloat(sum * 1000);
} else if (x >= '101' && x <= '200') {
var sum = (110 * x);
hasil.value = 'Rp.' + parseFloat(sum * 1000);
} else {
hasil.value = 'error!';
}
}
I have multiple functions like this and I am looking for a way to simplify it into just one function. Is it possible?