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;...
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...
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...
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]
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...
Java : Modify the selection sort algorithm to sort an array of integers in descending order....
Java : Modify the selection sort algorithm to sort an array of integers in descending order. describe how the skills you have gained could be applied in the field. Please don't use an already answered solution from chegg. I've unfortunately had that happen at many occasion ....... ........ sec01/SelectionSortDemo.java import java.util.Arrays; /** This program demonstrates the selection sort algorithm by sorting an array that is filled with random numbers. */ public class SelectionSortDemo { public static void main(String[] args) {...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should...
PLease code a C++ program that prompts a user to enter 10 numbers. this program should read the numbers into an array and find the smallest number in the list, the largest numbers in the list the sum of the 10 numbers and the average of the 10 numbers please use file i/o and input measures for Handling Errors in C++ When Opening a File
Hello, I feel like I am super close but I can not figure out why my...
Hello, I feel like I am super close but I can not figure out why my C++ code it not displaying the proper medium. Thank you! Here is an example of the output: Input : a[] = {1, 3, 4, 2, 6, 5, 8, 7} Output : Mean = 4.5 Median = 4.5 Code so far:   #include <iostream> using namespace std; int main() { int a[100]; int n,i,sum=0; float mean, medium; //read array size // read array cout<<"Enter array size:...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT