jeudi 8 novembre 2018

Javascript - improving on a nested if-else

I have a horrible nested if. There could in the future be even more lines.

if (people < 10) {
    price = 500;
} else if (people >= 10 && people < 25) {
    price = 350;
} else if (people >= 25 && people < 100) {
    price = 250;
} else if (people >= 100) {
    price = 200;
}

The price goes down as the volume goes up. How do I refactor this to make it more maintainable/readable?

Edit: I tried a switch and it was not any better?

Aucun commentaire:

Enregistrer un commentaire