## DEV Community π©βπ»π¨βπ» is a community of 966,904 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Deepak Raj

Posted on • Updated on

# Day 2 - 10DaysOfJavaScript

### Day 2: Conditional Statements: If-Else

• An integer value score is provided for a students test
• 0 β€ score β€ 30
• It must return the letter corresponding to grade
``````function getGrade(score) {
if(score<=5) {
}else if(score<=10) {
}else if(score<=15) {
}else if(score<=20) {
}else if(score<=25) {
}else if(score<=30) {
}
}

``````

### Day 2: Conditional Statements: Switch

• A string is provided where its length is 1 β€ s β€ 100
• Given the following legend, return the correct value based on the first letter
``````function getLetter(s) {
let letter;
switch (true) {
case 'aeiou'.includes(s[0]):
letter = 'A';
break;
case 'bcdfg'.includes(s[0]):
letter = 'B';
break;
case 'hjklm'.includes(s[0]):
letter = 'C';
break;
case 'npqrstvwxyz'.includes(s[0]):
letter = 'D';
break;
}
return letter;
}

``````

Day 2: Loops

• Given a string of s of any length
• Output, in order, the vowels of that string on each new line
• Right after, output, in order, the consonants of that string on each new line
``````/*
* Complete the vowelsAndConsonants function.
* Print your output using 'console.log()'.
*/
function vowelsAndConsonants(s) {
let vowels = ['a','e','i','o','u'];

for(let v of s) {
if(vowels.includes(v))
console.log(v);
}
for(let v of s) {
if(!vowels.includes(v))
console.log(v);
}
}
string = 'javascriptloops'
vowelsAndConsonants(string)
``````

### More Articles by Author

React β€οΈ to encourage Author.

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];
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';
...
}
``````

## π Browsing with dark mode makes you a better developer.

It's a scientific fact.