You can easily get odd and even numbers from the codes below. Suppose I set the odd and even number between 1 and 30. First of all, let’s declare 2 variables and then run for loop between 1 and 30. Then you need to use a reminder (i% 2 == 0) in if condition for even number. Then the odd number will be found automatically in the else condition.

<script>
var
even = “”;
var
odd = “”;
var i;
for (i = 0; i < 30; i++) {
if (i % 2 == 0) {
even += “No.” + i + “<br>”;
}
else{
odd += “No.” + i + “<br>”;
}
}
</script>

--

--