How do i enter to display all three-digit numbers multiple of three on javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How do i enter to display all three-digit numbers multiple of three on javascript?

Как вывести все трехзначные числа кратные трем на экран в javascript?

13th Jan 2018, 11:03 AM
Марсель Халимов
5 Answers
+ 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
13th Jan 2018, 11:24 AM
Ipang
+ 6
You're welcome : )
13th Jan 2018, 12:18 PM
Ipang
+ 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);
13th Jan 2018, 12:33 PM
lion
lion - avatar
+ 1
thanks
13th Jan 2018, 11:52 AM
Марсель Халимов
0
How to find the sum of all three-digit numbers multiples of four?Javascript
13th Jan 2018, 12:19 PM
Марсель Халимов