Question

JAVASCRIPT/HTML: Please read 10 numbers that are listed below, edit the code given to sort the...

JAVASCRIPT/HTML:
Please read 10 numbers that are listed below, edit the code given to sort the numbers from least to greatest, and then print those numbers.
10 numbers = { 9, 3, 2, 1, 10, 30, 4, 6, 7, 8}
Submit the code and a screenshot of the output.

[Reference JavaScript code]

<html>
<body>
<H1>prompt()</h1>
<p id="pro"></p>

<script>
// Array creation
var num= new Array();

var ix = 0;
// Read 10 numbers
for (ix = 0; ix < 10; ix++)
{num[ix] = prompt("Enter a number");
}
// Write 10 numbers
document.writeln( num + "<br>");
// Write 10 numbers one by one
for(ix = 0; ix < 10; ix++)
{
document.writeln( num[ix] + "<br>");
}
</script>
</body>
</html>

Homework Answers

Answer #1
<!DOCTYPE html>
<html>
<body>
<H1>prompt()</h1>
<p id="pro"></p>

<script>
// Array creation
var num= new Array();

var ix = 0;
// Read 10 numbers
for (ix = 0; ix < 10; ix++)
{num[ix] = parseInt(prompt("Enter a number"));
}

n = num.length;
for (var i = 0; i < n - 1; i++) {
for (var j = 0; j < n - i - 1; j++) {
            if (num[j] > num[j + 1]) {
                var temp = num[j];
                num[j] = num[j + 1];
                num[j + 1] = temp;
            }
        }
        
    }

// Write 10 numbers
document.writeln( num + "<br>");
// Write 10 numbers one by one
for(ix = 0; ix < 10; ix++)
{
document.writeln( num[ix] + "<br>");
}
</script>
</body>
</html>

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
[Lab Task HTML/JAVASCRIPT] Please read 10 numbers that are list below, sort the numbers and then...
[Lab Task HTML/JAVASCRIPT] Please read 10 numbers that are list below, sort the numbers and then print those numbers. 10 numbers = { 9, 3, 2, 1, 10, 30, 4, 6, 7, 8} Output should have a sorted list [Reference JavaScript code] <html> <body>     <H1>prompt()</h1>     <p id="pro"></p>     <script>        // Array creation        var num= new Array();               var ix = 0;        // Read 10 numbers        for (ix = 0; ix < 10; ix++)...
Please linked both files. For this assignment you need to create a ToDo list using Javascript,...
Please linked both files. For this assignment you need to create a ToDo list using Javascript, along with HTML and CSS. Begin by creating a HTML page called todo.html. Then create a Javascript file called todo.js and link it in to the HTML page using a script tag. All Javascript for the assignment must be in the separate file. (For CSS, feel free to include styles in a style block at the top of the HTML page, or to link...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you...
PART B- Javascript Using a text editor (VS Code or Notepad) and a web browser, you will demonstrate how to create an HTML file, externally link a JavaScript file, and write some source code in the JavaScript file. a..Create two blank files to be an HTML file and a JavaScript file. The file names should be partA.html and partA.js. b.. Create a basic HTML webpage structure. c..Link the JavaScript file to the HTML file using the <script> tag. d.. Prompt...
For this assignment you'll be creating an application that has the user input a subtotal, tax...
For this assignment you'll be creating an application that has the user input a subtotal, tax rate and tip percentage and then displays the sales tax, tip amount and the total. You'll use JQuery instead of the getElementByX functions AND you will display all messages on the page (no alert or prompt boxes) The starter file is based off of the Lab 2 sales_tax application. Feel free to borrow code from your lab solution but realize you will need to...
In the previous assessment, you used a static set of named variables to store the data...
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT