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

Task 1: HTML and CSS Create a website using HTML5 and CSS3 only. Please no JavaScript...
Task 1: HTML and CSS Create a website using HTML5 and CSS3 only. Please no JavaScript or Bootstrap. Website theme can be anything you want: a country, a town, a place, a hobby, people (yourself, your family...), pets, flowers, food, or anything that you find interesting or useful. It may be about real people/places/things or fictitious. Part 1: Content (HTML) After you decide the theme of your website, create HTML pages with the content you want to present. Remember to...
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...
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...
●In this task, the quick sort algorithm selects the first element in the list as the...
●In this task, the quick sort algorithm selects the first element in the list as the pivot. Revise it by selecting the median among the first, middle, and last elements in the list. ● Write the algorithm for searching for entries using linear probing. ● Write the algorithm for removing entries using linear probing. ● Create a diagram similar to the one above that shows the hash table of size 11 after entries with the keys 34, 29, 53, 44,...
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
write a javascript function called cal_modes that will take a List of numbers or strings as...
write a javascript function called cal_modes that will take a List of numbers or strings as input and returns a List of the most frequent values. If there's only one most-frequent value, it returns a single-element List. example cal_modes([3,4,5,5]) should return [5] cal_modes([8.9, 1, 1]) should return [1] cal_modes([2.5, -2, -2, 2.5]) should return [2.5] cal_modes([3,3,4,4]) should return [3,4] cal_modes([3,4,5]) should return [3,4,5], because all occur with equal frequency cal_modes(["hi", "what", "where", "hi"]) should return ["hi”]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT