Computer Science, asked by guddu3960, 1 year ago

write a event driven program in javascript to display even numbers from 1 to50​

Answers

Answered by ankurbadani84
6

Program as below :-

function* range(begin, end, filter, ite = 1) {

       for (var x = begin; x != end; x += ite) {

               if (filter(x)) {

                       yield x;

               }

       }

}

 

function is_even(i) {  return i % 2 == 0;  }

 

window.onload = function() {

  for (var i of range(1,50,(i) => is_even(i))) {

       console.log(x);

}

}

Answered by Arslankincsem
3

An event driven program in JavaScript to display even numbers from 1 to 50 is the following:

function printEven(50) {

 for (let i=1; i<=50; i++) {

   if(i % 2 === 0) {

     console.log(i);

   }

 }

}

The output of the above written program will be something of this manner

2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50

Similar questions