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>
<!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>
Get Answers For Free
Most questions answered within 1 hours.