javascript

JavaScript to print Even Numbers within a Range!

Let’s write a JavaScript program to print Even Numbers within a given range.

First, to find an Even number it is very simple, divide the number by 2 if the remainder is zero then it’s an Even number.

Example if you give the start and end range from 10 to 20, the program has to print 10, 12, 14, 16, 18, 20. So let’s write a simple snippet now.

The above script should print the values in the console as expected.

Let’s write a dynamic script with HTML to get the start and end range from the user and print the output on the browser.

Just go through the above script to understand it.

You can also see the demo of the above script:

demo

Related Posts

3 thoughts on “JavaScript to print Even Numbers within a Range!

  1. There’s a bug. When I enter 3 at start and 20 at the end. Program doesnt work. 4 and 30,5 and 40,….,don’t work. Help.

Leave a Reply