Answer:
Following are the program code to display the even number in JavaScript is given below .
Step-by-step explanation:
For creating this we are using two files
HTML code:
<html>
<head>
<title> Display single digit even numbers from 1 to 10.</title>
</head>
<body>
</body>
</html>
JavaScript code (.js)
for (var i=1; x<10; i++) // iterating loop
{ switch(i%2) // check the condition of even number
{
case 0:
console.log(i + " "); // display even number
break;
}
}
Output:
2 4 6 8
Following are the description of program
- In this program we have created the two file first is HTML file and second is JavaScript file.
- The HTML file simply display the message on the web page .
- In the JavaScript code we iterated the for loop from 1 to 10 .In this for loop we checking the condition in the switch block .
- The case 0 described the even number and it executed that block inside the case 0.
- Finally print the even number .