Write a event driven program in JavaScript to display even numbers from 2 to 50
Answers
Answered by
4
Answer:
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);
}
}
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
English,
5 months ago
Chemistry,
5 months ago
Social Sciences,
5 months ago
Math,
11 months ago
Math,
11 months ago