0
How do i enter to display all three-digit numbers multiple of three on javascript?
Как вывести все трехзначные числа кратные трем на экран в javascript?
5 ответов
+ 6
Since you need three-digit number you can start from 100, use a for loop with verification inside to check whether the number is fully divisible by three:
var topLimit = 500; // change this as necessary
for(var i = 100; i < topLimit; i++)
{
if(i % 3 == 0)
{
// Your code here ...
}
}
Hth, cmiiw
+ 6
You're welcome : )
+ 3
For the main question: start from 102 (the first three-digit multiple of three) and up to 999 with a step of 3. There will be no need to check if i%3==0 because now you know it's always a multiple of 3. Like this:
for(var i = 102; i <= 999; i += 3)
document.write(i + "<br />");
For the sum of multiples of 4:
var sum = 0;
for(var i = 100; i <= 999; i += 4)
sum += i;
document.write(sum);
+ 1
thanks
0
How to find the sum of all three-digit numbers multiples of four?Javascript