
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
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
- Related Articles
- Finding the 1-based index of a character in alphabets using JavaScript
- Finding number plate based on registration number in JavaScript
- Finding astrological signs based on birthdates using JavaScript
- Finding the 1-based index score of a lowercase alpha string in JavaScript
- Finding life path number based on a date of birth in JavaScript
- Finding median index of array in JavaScript
- Finding the height based on width and screen size ratio (width:height) in JavaScript
- Finding reversed index of elements in arrays - JavaScript
- How to get index in a sorted array based on iterator function in JavaScript?
- Select total from a MySQL table based on month
- Finding day of week from date (day, month, year) in JavaScript
- Do a select in MySQL based only on month and year?
- How to calculate quarter start date or end date based on a given date in Excel?
- Group by day/month/week based on the date range in MongoDB
- How to add element based on index in android CopyOnWriteArrayList?

Advertisements