- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Finding quarter based on month index in JavaScript
Problem
We are required to write a JavaScript function that takes in the 1-based month index and return the quarter, which the month falls in.
Example
Following is the code −
const month = 7; const findQuarter = (month = 1) => { if (month <= 3) { return 1 } else if (month <= 6) { return 2 } else if (month <= 9) { return 3 } else if (month <= 12) { return 4 } } console.log(findQuarter(month));
Output
Following is the console output −
3
Advertisements
To Continue Learning Please Login
Login with Google