Computer Science, asked by kumaririya1938, 2 months ago

Write down a program to print odd numbers starting from 1 and ending up to 9 in JavaScript​

Answers

Answered by cnestofficial123
1

Answer:

function print(){  

var i;  

var write = document.getElementsByTagName('h1')[0];  

for(i = 20; i <= 70; i++){  

  if((i % 2) == 0){  

   continue; //if num is odd, skip it.  

  }  

  write.innerHTML += i + '<br/>';  

}  

}  

print(); //invoke print function  

Use continue statement to skip an iteration of the loop if given condition is satisfied.

To print a random odd number from 20 to 70 use this:

function generate_random_odd(min,max){  

var num = Math.floor(Math.random() * (max - min)) + min;  

if((num % 2) == 0){  

 return num + 1;  

}  

else {  

 return num;  

}  

}  

document.getElementsByTagName('h1')[0].innerHTML = generate_random_odd(20,70);

Explanation:

Answered by annuvava
0

C Program is the answer.

Similar questions