Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this exercise, you will write a while statement that displays all odd numbers

ID: 3880358 • Letter: I

Question

In this exercise, you will write a while statement that displays all odd numbers between 1 and 100 on the screen. Complete the steps below:

1. Open Notepad++ and create a new document.

2. Type the <!DOCTYPE> declaration, <html> element, header information, and <body> element. Use the strict DTD and “Odd Numbers” as the content of the <title> element.

3. Create a script section in the document body with a while statement that displays all odd numbers between 1 and 100 on the screen.

Explanation / Answer

<!DOCTYPE html>

<html>

<head>

<title>Odd numbers between 1 and 100 </title>

</head>

<body>

<script>

var oddArray = [];

var i = 1;

while (i < 100) {

if(i % 2 != 0) {

oddArray.push(i);

i = i + 2;

}

}

for (var j = 0; j < oddArray.length; j++) {

//print(oddArray[j]); // Display by your convenient way

console.log(oddArray[j]);

}

</script>

</body>

</html>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote