I am curious to know why this was closed as "unclear what you are asking".
I would need to match the average score to a letter grade. That means
if (90 < avg && avg < 100) { return 'A'; } // and so on until 'F', with 5 if-else statements
That's a lot of repetition, and the ranges I'm matching to are of the same length. Is there a more efficient way to do this? By efficient, I mean not having to repeat the if-else statement 5 times
There were 8 answers given, there were hot discussions to the point in the comments. It seems everybody got the problem, except for 3 people who voted to close, the same two voted to delete it shortly afterwards.
It's worth mentioning that OP faced difficulties to add their code snippet.
I tried adding code, but it won't format correctly (I'm new to stackoverflow). The instructions say to type two whitespaces for line break but that never worked...
Their comment was ignored, and the question was closed ignorantly (in my opinion).
UPDATE
The question was closed again as "too broad". Please, put yourself in OP's shoes, and read the explanation
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer.
The problem was outlined (getting rid of multiple if-else statements). The scope was specific (grading system).
Avoid asking multiple distinct questions at once.
One question was asked.
What exactly could OP improve? No one bothered to explain. It was closed again without letting OP read this discussion, and/or make changes. I love this community :)
avg
variable. You might have conditions that are mutually exclusive and check different things, e.g.,isUserAdmin else if isSystemInSpecialMode else if wasThereError else if isItTheSecondThursday
- checking different things. This is more rare. The case OP had is bound to have come up before as a question. Maybe even for grades.if / else
which is exactly what the OP wanted to avoid. The other doesn't even have an accepted answer. And finally none of the answers usesMap
andPredicate
.