Question

[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++)

       {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>

[Insertion Sort in pseudocode] [What should be the java code in order to sort]

i ← 1

while i < 10

    j ← i

    while j > 0 and num[j-1] > num[j]

        swap A[j] and A[j-1]

        j ← j - 1

    end while

    i ← i + 1

end while

{WHAT I AM STUCK ON / INCOMPLETE CODE FROM PSEUDOCODE}

        var i;
                var j;
                var temp;
                i = 1;
                
                while (i< 10) {
                        j = i;
                        while (j > 10 && num[j-1] < num[j]) {

Homework Answers

Answer #1
<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>");
    }

    var i = 1;
    while (i < 10) {
        var j = i;
        while (j > 0 && num[j - 1] > num[j]) {
            var temp = num[j];
            num[j] = num[j - 1];
            num[j - 1] = temp;
            j--;
        }
        i++;
    }

    // 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
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;...
HTML Assignment Question 7: Which of the following is NOT a correct description of JavaScript: A....
HTML Assignment Question 7: Which of the following is NOT a correct description of JavaScript: A. JavaScript is an interpreted/scripting language. B. JavaScript is a high-level programming language. C. JavaScript can be executed in web browser by JavaScript engine to make web pages more interactive, and user-friendly. D. JavaScript is a part of Java extension. Question 8: To provide JavaScript for an HTML document, you must add a <script> element in the <head> part of the document that either includes...
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...
Need HTML and JS code. Write a Javascript function named RandomString(randomStringLength) that returns a string filled...
Need HTML and JS code. Write a Javascript function named RandomString(randomStringLength) that returns a string filled with random characters where the length of the random string is defined by the input parameter. HINT: Use a for-loop, Math.random, and the fact that the alphabet has 26 characters (remembering that we can have both lower-case and upper-case characters in a string). This is what I have: <html> <!-- inputbox.html Jerry Davis --> <!-- Web page that sets the correct letter value. -->...
Sorting – Insertion Sort Sort the list 0, 3, -10,-2,10,-2 using insertion sort, ascending. Show the...
Sorting – Insertion Sort Sort the list 0, 3, -10,-2,10,-2 using insertion sort, ascending. Show the list after each outer loop. Do this manually, i.e. step through the algorithm yourself without a computer. This question is related to data structure and algorithm in javascript (.js). Please do not copy from stackabuse or stackoverflow, Please explain that algorithm with comments. i really want to learn this concept.
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort...
in C++ Please and thanks Here is a list of 6 numbers. Use the selection sort algorithm to sort this list. Fill in this table with each iteration of the loop in the selection sort algorithm. Mark the place from which you are looking for the 'next smallest element'. In this display, the upper numbers are the indices, the lower numbers are in the corresponding positions. Use the several rows provided to show the sequence of steps. 0 1 2...
Hello, I am trying to create a java script code that can arranges the input lowest,...
Hello, I am trying to create a java script code that can arranges the input lowest, highest, finding average, sort them and the clear form functionality. I managed to create the code that sorts the number input from lowest to highest but I am stuck on the rest. See the code below Please help. <!DOCTYPE> <html> <head> <title>EXAM01_01</title> <style type="text/css"> form{color:black;background-color:lightgray;border:6px solid black;border-width:4px;width:450px;margin:1px;padding:1px;} #ans1,#ans2,#ans3,#ans4,#numbers{background-color:white;border:4px solid black;} input[type="button"]{color:black;background-color:red;border:4px solid black;} input[type="text"]{margin:2px;} div.title{color:white;background-color:black;float: left; width: 450px; text-align:center;} </style> <script>    function readNumbers()...
Write a MIPS assembly program that sorts an array using bubble sort translating the C code...
Write a MIPS assembly program that sorts an array using bubble sort translating the C code int main(void) { int array[] = {10, 2, 7, 5, 15, 30, 8, 6}; // input array int arraySize = sizeof(array)/sizeof(array[0]); bool swapped = true; int j = 0; int tmp; while (swapped) { swapped = false; //Note : "j" , "arraySize - j" are optimizations to the bubble sort algorithm j++; // j= sorted elements int i=0; /* "arraySize - j" is used...
PYTHON The following code implements this algorithm to sort a list of numbers in ascending order....
PYTHON The following code implements this algorithm to sort a list of numbers in ascending order. But some code is missing as indicated by '?'. def sort_in_place(list_num): for i in range(?): for j in range(?): if ?: temp = list_num[j] list_num[j] = list_num[i] list_num[i] = temp my_list = [23,1,45,20,13,-34] sort_in_place(my_list) print(my_list) Modify the three lines of code in the program below so that the output is [-34, 1, 13, 20, 23, 45]
1. Shown below is the code for the insertion sort consisting of two recursive methods that...
1. Shown below is the code for the insertion sort consisting of two recursive methods that replace the two nested loops that would be used in its iterative counterpart: void insertionSort(int array[]) { insert(array, 1); } void insert(int[] array, int i) { if (i < array.length) { int value = array[i]; int j = shift(array, value, i); array[j] = value; insert(array, i + 1); } } int shift(int[] array, int value, int i) { int insert = i; if (i...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT