Hello Programmers/Coders, Today we are going to share solutions of Programming problems of HackerRank, 10 Days Of JavaScript. At Each Problem with Successful submission with all Test Cases Passed, you will get an score or marks. And after solving maximum problems, you will be getting stars. This will highlight your profile to the recruiters.
In this post, you will find the solution for Day 2: Conditional Statements: Switch in JavaScript-HackerRank Problem. We are providing the correct and tested solutions of coding problems present on HackerRank. If you are not able to solve any problem, then you can take help from our Blog/website.
Use “Ctrl+F” To Find Any Questions Answer. & For Mobile User, You Just Need To Click On Three dots In Your Browser & You Will Get A “Find” Option There. Use These Option to Get Any Random Questions Answer.
Introduction To JavaScript
JavaScript is a lightweight, cross-platform, and interpreted scripting language. It is well-known for the development of web pages, many non-browser environments also use it. JavaScript can be used for Client-side developments as well as Server-side developments. JavaScript contains a standard library of objects, like Array, Date, and Math, and a core set of language elements like operators, control structures, and statements.
Advantages of JavaScript
The merits of using JavaScript are −
- Less server interaction − You can validate user input before sending the page off to the server. This saves server traffic, which means less load on your server.
- Immediate feedback to the visitors − They don’t have to wait for a page reload to see if they have forgotten to enter something.
- Increased interactivity − You can create interfaces that react when the user hovers over them with a mouse or activates them via the keyboard.
- Richer interfaces − You can use JavaScript to include such items as drag-and-drop components and sliders to give a Rich Interface to your site visitors.
Link for the Problem – Day 2: Conditional Statements: Switch – Hacker Rank Solution
Day 2: Conditional Statements: Switch– Hacker Rank Solution
Problem:
Objective
In this challenge, we learn about switch statements. Check out the attached tutorial for more details.
Task
![Day 2: Conditional Statements: Switch in Javascript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 2 image 17](https://technorj.com/wp-content/uploads/2021/12/image-17.png)
Function Description
Complete the getLetter function in the editor below.
getLetter has the following parameters:
- string s: a string
Returns
- string: a single letter determined as described above
Input Format
Stub code in the editor reads a single string denoting from stdin.
Constraints
![Day 2: Conditional Statements: Switch in Javascript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 3 image 16](https://technorj.com/wp-content/uploads/2021/12/image-16.png)
Sample Input 0
adfgt
Sample Output 0
A
Explanation 0
![Day 2: Conditional Statements: Switch in Javascript | 10 Days Of JavaScript Solutions | HackerRank Programming Solutions [💯Correct] 4 image 15](https://technorj.com/wp-content/uploads/2021/12/image-15.png)
Day 2: Conditional Statements: Switch – Hacker Rank Solution
function getLetter(s) { let letter; // Write your code here switch (true) { case "aeiou".includes(s[0]): letter = "A"; break; case "bcdefg".includes(s[0]): letter = "B"; break; case "hijklm".includes(s[0]): letter = "C"; break; case "nopqrstuvwxyz".includes(s[0]): letter = "D"; break; } return letter; }
You actuɑlly make it seem so eaѕу together with your presеntation but I find this topic to be really something which I believe I would never understand.
It sort of feels too ϲomplex and very huge for me.
I am looking ahead for your next post, I’ll attempt
to get the hang of it!