
- 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 the count of numbers divisible by a number within a range using JavaScript
Problem
We are required to write a JavaScript function that takes in a range of two integers as the first argument and a number as the second argument.
Our function should find all the numbers divisible by the input number in the specified range and return their count.
Example
Following is the code −
const range = [6, 57]; const num = 3; const findDivisibleCount = (num = 1, [l, h]) => { let count = 0; for(let i = l; i <= h; i++){ if(i % num === 0){ count++; }; }; return count; }; console.log(findDivisibleCount(num, range));
Output
18
- Related Articles
- Finding sum of all numbers within a range in JavaScript
- Finding sequential digit numbers within a range in JavaScript
- Finding the count of total upside down numbers in a range using JavaScript
- Count the numbers divisible by ‘M’ in a given range in C++
- Greatest number divisible by n within a bound in JavaScript
- Prime numbers within a range in JavaScript
- Python - Find the number of prime numbers within a given range of numbers
- Armstrong number within a range in JavaScript
- Finding a pair that is divisible by some number in JavaScript
- Count numbers in a range that are divisible by all array elements in C++
- Summing cubes of natural numbers within a range in JavaScript
- Counting prime numbers that reduce to 1 within a range using JavaScript
- Python Program to Print all Numbers in a Range Divisible by a Given Number
- Golang Program to Print all Numbers in a Range Divisible by a Given Number
- Finding the largest 5 digit number within the input number using JavaScript

Advertisements