# Day 2

## Conditional Statements: If-Else

{% embed url="<https://www.hackerrank.com/challenges/js10-if-else/problem?isFullScreen=true>" %}

```javascript
function getGrade(score) {
    let grade;
    // Write your code here
    if (score > 25 && score <= 30) 
        grade = "A";
    else if (score > 20 && score <= 25)
        grade = "B";
    else if (score > 15 && score <= 20)
        grade = "C";
    else if (score > 10 && score <= 15)
        grade = "D";
    else if (score > 5 && score <= 10)
        grade = "E";
    else
        grade = "F";
        
    return grade;
}
```

## Conditional Statements: Switch

{% embed url="<https://www.hackerrank.com/challenges/js10-switch/problem?isFullScreen=true>" %}

```javascript
function getLetter(s) {
    let letter;
    // Write your code here
    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;
}
```

## Loops

{% embed url="<https://www.hackerrank.com/challenges/js10-loops/problem?isFullScreen=true>" %}

```javascript
/*
 * Complete the vowelsAndConsonants function.
 * Print your output using 'console.log()'.
 */
function vowelsAndConsonants(s) {
    const vowels = ["a","e","i","o","u"];
    const str = s.split("");
    const vowelsArr = [];
    const consonantsArr = [];
    for(let i = 0; i < str.length; i++)
        vowels.includes(str[i]) ? vowelsArr.push(str[i]) : consonantsArr.push(str[i]);
    for(let i = 0; i < vowelsArr.length; i++)
        console.log(vowelsArr[i]);
    for(let i = 0; i < consonantsArr.length; i++)
        console.log(consonantsArr[i]);
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://dailyjournal.gitbook.io/solutions/hackerrank-solutions/tutorials/10-days-of-javascript/day-2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
