loading...

re: Daily Challenge #68 - Grade Book VIEW POST

FULL DISCUSSION
 

Too much ternary operators...

const grade = (a,b,c) =>{
    const mean = (a + b + c) / 3;

    const prefix = mean % 10 < 5 ? '-': 
                   mean % 10 > 5 ? '+': '';

    return   mean < 59 ?          `F (${mean})`:
             mean < 70 ? `D${prefix} (${mean})` : 
             mean < 80 ? `C${prefix} (${mean})`: 
             mean < 90 ? `B${prefix} (${mean})` : 
                         `A${prefix} (${mean})`;

}
 

I've Started to write a c# answer only to find out I'm going the exact same route as your answer...

 

You could use something like that:

({"-1": "-", "1": "+", "0": ""})[mean.toString().localeCompare("5")]

Not tested but I believe it would work in JavaScript.

code of conduct - report abuse