Question

In: Computer Science

JavaScript (HTML) Task: Please read 10 numbers that are list below, sort the numbers and then...

JavaScript (HTML) Task:

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}

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

Solutions

Expert Solution

Code:

<html>
<body>
<script>
var numbers=new Array();               //array declaration
for (var i=0;i<10;i++)           //iterating loop ten times to take 10 numbers
      
       numbers[i]=prompt("Enter Number " + (i+1) + "")       //asking user to enter the 10 numbers
  
   document.writeln("Given Array is : " + numbers)       //printing the given array
  
   document.writeln("<br>"+"The Sorted Array is : " + numbers.sort(function(n1, n2){return n1 - n2}))
  
   //sorting the array using array.sort() function by default sort takes the values as strings so we will put compare function in it.
  
   var sorted_numbers=numbers.sort(function(n1, n2){return n1 - n2}); //sorting the array again to show values line by line
  
   //sorting and storing it in sorted_numbers

   document.writeln("<br>The Sorted Array : <br>")
   //printing sorted array numbers one by one
   for (var i=0;i<10;i++)
           document.writeln(sorted_numbers[i] + "<br>")
</script>
</body>
</html>

Code and Output Screenshots:

Note: if you have any queries please post a comment thanks a lot.. always available to help you..


Related Solutions

Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to...
Write the below code to use HTML and JavaScript. 1. a) Write a JavaScript program to display the current day and time. b) Write a JavaScript program to print the contents of the current window.   c) Write a JavaScript program where the program takes a random integer between 1 to 10 d) Write a JavaScript program to calculate multiplication and division of two numbers (input from the user). e)Write a JavaScript program to create a new string from a given...
Using HTML and JavaScript, receive a positive number, n, and output all prime numbers that are...
Using HTML and JavaScript, receive a positive number, n, and output all prime numbers that are smaller than n and have a digit 7. For example, if n is 100, the program should output 7, 17, 37, 47, 67, 71, 73, 79, and 97.
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
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 in CSS from a...
For this assignment you need to create a ToDo list using Javascript, along with HTML and...
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 in CSS from a...
Please take the code below and add some javascript to it. Please use javascript inline. Please...
Please take the code below and add some javascript to it. Please use javascript inline. Please be sure to specify within the webpage with something like 'Click here' too show what was done and how to activate it. Please post in a format that can be directly copied. Thank you in advance HINT: add some fun widgets to the page index-css.html: <!DOCTYPE html> <html lang="en"> <head> <!-- title for web page --> <title>Index-CSS Page</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1">...
Please use javascript. Starting with an array containing the numbers 1 through 10, use filter, map...
Please use javascript. Starting with an array containing the numbers 1 through 10, use filter, map and reduce to produce the following. Use console.log to display the results. a. An array of odd numbers b. An array of numbers divisible by 2 or 5 c. An array of numbers divisible by 3 squared d. The sum of the following: square the numbers divisible by 5
Look at the HTML below ( do NOT modify the HTML), Outer paragraph, outer list, div...
Look at the HTML below ( do NOT modify the HTML), Outer paragraph, outer list, div with 2 inner paragraphs and one inner list , create a CSS which will: Make the outer list text color blue , and make the outer (non div) paragraph blue, and the div inner list element pink also inside the div element make the first inner paragraph green, and in the div element the second paragraph blue, so that in order: blue-blue-green-blue-pink As a...
Given the HTML below ( do not modify the HTML), Outer paragraph, outer list, div with...
Given the HTML below ( do not modify the HTML), Outer paragraph, outer list, div with 2 inner paragraphs and one inner list , create a CSS which will: a) Make the outer list text color blue , and make the outer (non div) paragraph blue, and the div inner list element pink also inside the div element make the first inner paragraph green, and in the div element the second paragraph blue, so that in order: blue-blue-green-blue-pink b)As a...
Please create a PHP action codes for the HTML CODE provided below. <!DOCTYPE html> <html> <head>...
Please create a PHP action codes for the HTML CODE provided below. <!DOCTYPE html> <html> <head> <title> Project for keeping all your input </title> </head> <body> <h1>Welcome to this Web Based Test!!!</h1> <p>Please answer the following questions:</p> <hr/> <form action="" method="post"> Name: <input type="text" name="name" value=""> <font color=red>*</font><br/><br/> E-mail: <input type="text" name="email" value=""> <font color=red>*</font><br> <hr/> Choose your major area of study: <select name="major"> <option value="Digital Media" >Digital Media</option> <option value="Software" >Software</option> <option value="Security" >Security</option> <option value="Business" >Business</option> <option value="Other"...
Please Use JavaScript and HTML 5) Number guesser (easier) Create a number guessing name, using an...
Please Use JavaScript and HTML 5) Number guesser (easier) Create a number guessing name, using an input and a button to gather a number. The number to be guessed should be a hard-coded whole number between 1 and 20. Tell the user if the number is too high, equal to, or too low than a number you have hard-coded in your application. Remove the text in the input when the user clicks the button.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT