DEV Community

Discussion on: Day 2 - 10DaysOfJavaScript

Collapse
 
pentacular profile image
pentacular

It would be simpler without the grade variable.
You can just return the value directly.

I also suggest using more spaces and not writing if(x) which looks like a function call.

function getGrade (score) {
    if (score <= 5) {
        return "F";
    } else if (score <= 10) {
       ...
    }
}

Likewise here, although here we can also use better variable names.

function getLetter (string) {
    const letter = string[0];
    // Write your code here
    switch (true) {
        case 'aeiou'.includes(letter):
            return 'A';
        case 'bcdfg'.includes(letter):
            ...
    }
}

You already know that includes works on strings, so why stop now?
And let's use const if you're not going to reassign something.

function vowelsAndConsonants (string) {
    const vowels = 'aeiou';
    ...
}