Javascript program reformation
A. combine three loops into one loop and REPLACE FOR LOOP with a while loop to maintain the same result
<!DOCTYPE html>
<html><head><title>19.7 For
Loop</title>
<script language="javascript">
//numbers divisible by 5
for (i=1; i<=50; i++) {
if (i%5 == 0) document.write ("number divisible by
five is: " + i + "<br />");
} //for
document.write ("========================<br />");
//separator
//odd numbers divisible by 7
for (i=1; i<=50; i++) {
if ((i%7==0) && (i%2!=0)) document.write ("odd
number divisible by seven is: " + i + "<br />");
} //for
document.write ("========================<br />");
//separator
//even numbers divisible by 9
for (i=1; i<=50; i++) {
if ((i%9==0) && (i%2==0)) document.write
("even number divisible by nine is: " + i + "<br />");
} //for
document.write ("========================"); //separator
</script>
</head>
<body>
</body>
</html>
Code:
<!DOCTYPE html>
<html><head><title>19.7 For
Loop</title>
<script language="javascript">
//numbers divisible by 5
var div5="";//Variable to store the content obtained for condition
of divisability by 5
var div7="";//Variable to store the content obtained for condition
of divisability by 7
var div9="";//Variable to store the content obtained for condition
of divisability by 9
var i=1;
while (i<=50) {//while looping from 1 to 50
if (i%5 == 0) div5+="number divisible by five is: " + i + "<br
/>";
if ((i%7==0) && (i%2!=0)) div7+="odd number divisible by
seven is: " + i + "<br />";
if ((i%9==0) && (i%2==0)) div9+="even number divisible by
nine is: " + i + "<br />";
i++;//incrementing i
}
document.write(div5);//printing the html string to the
document
document.write ("========================<br />");
//separator
document.write(div7);//printing the html string to the
document
document.write ("========================<br />");
//separator
document.write(div9);//printing the html string to the
document
document.write ("========================"); //separator
</script>
</head>
<body>
</body>
</html>
Sample i/o:

Explanation:
A while loop is written to loop from 1 to 50 by using loop variable i. 3 variables were used to store the content that is being displayed on the screen. After the loop ends the whole variable is printed as the html text does not look at spaces and new lines.
Javascript program reformation A. combine three loops into one loop and REPLACE FOR LOOP with a...
Please help me with the following requirements for JavaScript. Write a function to take a temperature value in Celsius as an argument and return the equivalent temperature in Fahrenheit, basing it on the code from Hour 2. //Original Code <!DOCTYPE html> <html> <head> <title>Fahrenheit From Celsius</title> </head> <body> <script> var cTemp = 100; // temperature in Celsius var hTemp = ((cTemp * 9) /5 ) + 32; document.write("Temperature in Celsius: " + cTemp + " degrees<br/>"); document.write("Temperature in Fahrenheit: "...
In this Javascript code, why are 2 for loops needed? could you please explain this to me. This is the outcome * ** *** **** ***** ****** ******* ******** ********* the code is <html> <head> <title></title> <script> showStars(10); function showStars(rows){ for(var i = 0; i < rows; i++){ var pattern = ""; for(var j...
<!DOCTYPE HTML>
<html lang="en">
<title>JavaScript Array Lab</title>
<script src="script.js"></script>
<body>
<p>To test your function,
call divideArray()
from the JavaScript console in the browser.</p>
</body>
</html>
Don't edit your code on the above code and do not copy from
others', plz!
// Put your solution here in script.js
Write the function divideArray() in script.js that has a single numbers parameter containing an array of integers. The function should divide numbers into two arrays, evenNums for...
I am trying to make it so that radio buttons when clicked execute a javascript file. I have to to have the exercises in external files. Here is what I have so far. I am reusing a script that was used to make radio buttons switch CSS files so I think I have to change the set attribute options. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <p> 4.2 Output: The first 20 Fibonacci numbers, which are...
Please modify the follow source code to also include the following: 1. Add two more flights from these two airlines: United and AA, and makeup all the related information. Make sure the user can pick those flight numbers (United & AA) form the prompt box. 2. Add an array to hold "Departure Time" for all the flights. (Time format: "0800A", "1135P" ...) 3. If the user type in a flight number is not in the flight record, send out a...
Javascript + HTML, no JQuery please. So, Im trying to figure out how to send an alert if the value of my selection is "0". I will be using this for a validation form assignement. So if the user leaves the selection on the default "0" value I can prompt the user to pick a valid option which would be 1+. Not sure how to access this value. Example code below: <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Form Validation</title>...
This is an HTML and javascript code that I tried to replicate form this video but it wouldn't work for me for some reason can you help me fix this issue. thanks, https://youtu.be/F7C30e7gR2Y <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>cicle Animation in js</title> <style> body { height: auto; margin: 0; } #ocean { position: absolute; width: 100%; min-height: 100%; background-image: -webkit-gradient(linear, left bottom, left top, color-stop(0, 50, 150)), color-stop(0.50, rgb(0, 150, 255)); } .wave { background: blue ; display:...
In an external JavaScript file, you need to create two global variables for the Quarter name array and the Sales amount array. Create an anonymous function and connect it to the onclick event of the Add to Array button that adds the values from the fields (Quarter and Sales) to the respective arrays. Create an anonymous function and connect it to the onclick event of Display Sales button displays the contents of the arrays, displays the sum of all the...
Create an HTML form that takes these inputs: Number of rows, and number of columns. This form will submit to a PHP page. Create that page that will accept input from the HTML form and generates the table from the user's input. I already have the portion that generates the table based on user input by using Javascript in an HTML page, I just need to know how to generate the table using a PHP page instead. Here's the code...
JAVASCRIPT/JQUERY Hello I would like some help understanding jQuery. Here are the directions: Write a program that creates the following table: Course Course Name Day Time IMS115 Windows 10 Monday 6 PM IMS215 Office 2016 Wednesday 5 PM MIS200 Java Thursday 9 AM MTH105 Business Math Saturday 10 AM Using jQuery, select every other odd row and change the font color to blue and make it bold. And here is my code: Chapter4.html <!DOCTYPE html> <html> <head> <link rel="stylesheet" href="Chapter4.css">...