Write a Javascript code to print all the odd numbers from 15 backwards to 3
Answers
Answered by
16
<script type=”text/javascript”>
function printOddNumbers(){
var counter;
for(counter=15;counter<=15;counter=counter-1)
{
if(counter%2!=0)
{
document.write(counter+”<br/>”);
}
may be its help u
}
}
printOddNumbers();
</script>
function printOddNumbers(){
var counter;
for(counter=15;counter<=15;counter=counter-1)
{
if(counter%2!=0)
{
document.write(counter+”<br/>”);
}
may be its help u
}
}
printOddNumbers();
</script>
Answered by
3
Below are the program in java script for the above question:
Explanation:
script (this is the tag which is inside the angular tag)//script open tag.
for(var i=15;i>=3;i--) // for loop.
{
if(!(i%2==0)) // check for the odd number.
document.write(i); // print the odd number.
}
script (this is the tag which is inside the angular tag started by '/' symbol)//script closing tag.
Output:
- The output are --
15
13
11
9
7
5
3
Code explanation:
- There is a for loop which runs for the "i" variable whose value starts from the 15 and ends in 3.
- The if condition checks the number is odd or not by dividing it to 2.
- Then the "document.write" statement print the number followed by space.
Learn More:
- Java Script : https://brainly.in/question/6445484
- Java Script : https://brainly.in/question/11722848
Similar questions