Question

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()
   {
       var x=document.getElementById("numbers");
       var numbers=x.value.trim();
       var array=numbers.split(" ");
       var array2=[];
       for(var i=0;i<array.length;i++)
       {
           if( array[i]!="") array2.push(array[i]);
       }  
           var y=array2.sort(function (a,b){return a-b;});
           alert(y.toString());
   }

          
   function readHighest()
   {
       var x=document.getElementById("numbers");
       var numbers=x.value.trim();
       var array=numbers.split(" ");
       var array2=[];
       for(var i=0;i<array.length;i++)
       {
           if( array[i]!="") array2.push(array[i]);
       }  
           var y=array2.sort(function (a,b){return a-b;});
           alert(y.toString());
   }

   function readAverage()
   {
       var x=document.getElementById("numbers");
       var numbers=x.value.trim();
       var array=numbers.split(" ");
       var array2=[];
       for(var i=0;i<array.length;i++)
       {
           if( array[i]!="") array2.push(array[i]);
       }  
           var y=array2.sort(function (a,b){return a-b;});
           alert(y.toString());
   }

   function readSort()
   {
       var x=document.getElementById("numbers");
       var numbers=x.value.trim();
       var array=numbers.split(" ");
       var array2=[];
       for(var i=0;i<array.length;i++)
       {
           if( array[i]!="") array2.push(array[i]);
       }  
           var y=array2.sort(function (a,b){return a-b;});
           alert(y.toString());
   }

          
   function readClear()
   {
       var x=document.getElementById("numbers");
       var numbers=x.value.trim();
       var array=numbers.split(" ");
       var array2=[];
       for(var i=0;i<array.length;i++)
       {
           if( array[i]!="") array2.push(array[i]);
       }  
           var y=array2.sort(function (a,b){return a-b;});
           alert(y.toString());
   }  
      
  

</script>  
</head>
<body>
   <form>
   <div class="title"><label>EXAM01_01</label></div>
   <p style="clear:both;" />
   <div style="float:left;width:150px;"><label>Enter Numbers:</label></div><div style="float:left;"><input type="text" id="numbers" /></div>
   <p style="clear:both;" />
   <div style="float:left;width:150px;"><label>Sorted List:</label></div><div style="float:left;"><input type="text" id="ans4" /></div>
   <p style="clear:both;" />
   <div style="float:left;width:150px;"><label>Lowest:</label></div><div style="float:left;"><input type="text" id="ans1" /></div>
   <p style="clear:both;" />
   <div style="float:left;width:150px;"><label>Highest:</label></div><div style="float:left;"><input type="text" id="ans2" /></div>
   <p style="clear:both;" />
   <div style="float:left;width:150px;"><label>Average:</label></div><div style="float:left;"><input type="text" id="ans3" /></div>
   <p style="clear:both;" />
   <div style="text-align:center;">
   <input type="button" value="Lowest"   onclick="readNumbers();"   />
   <input type="button" value="Highest" onclick="readHighest();"/>
   <input type="button" value="Average" onclick="Average();"/>
   <input type="button" value="Sort"    onclick="Sort();"/>
   <input type="button" value="Clear"    onclick="Clear();"/>
   </div>
   </form>
</body>
</html>

Homework Answers

Answer #1

Here is a code to do so:






Here is the sample output of how my code runs.


IF the answer helped you please upvote and in case you have any doubts post a comment, i will surely help you out.

Code:

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 readLowest()

{

// extract the numbers from the text box

   var x=document.getElementById("numbers");

var numbers=x.value.trim();

var array=numbers.split(" ");

var array2=[];

for(var i=0;i<array.length;i++)

{

if( array[i]!="") array2.push(array[i]);

}

// initialise the minimum value variable with the first element

// then iterate through the entire array, if any element smaller

// than the minimumValue appears, change the minimum to that.

        var minimumValue = parseInt(array2[0]);

for(var i=1;i<array2.length;i++)

    {

    if( parseInt(array2[i])<minimumValue)

     minimumValue = parseInt(array2[i]);

    }

// show that result in the text box.

document.getElementById("ans1").value = (minimumValue.toString());

}

function readHighest()

{

// extract the numbers from the text box

var x=document.getElementById("numbers");

var numbers=x.value.trim();

var array=numbers.split(" ");

var array2=[];

for(var i=0;i<array.length;i++)

{

if( array[i]!="") array2.push(array[i]);

}

// initialise the minimum value variable with the first element

// then iterate through the entire array, if any element smaller

// than the minimumValue appears, change the minimum to that.

        var maximumValue = parseInt(array2[0]);

for(var i=1;i<array2.length;i++)

    {

    if( parseInt(array2[i])>maximumValue)

     maximumValue = parseInt(array2[i]);

    }

// show that result in the text box.

document.getElementById("ans2").value = (maximumValue.toString());

}

function readAverage()

{

var x=document.getElementById("numbers");

var numbers=x.value.trim();

var array=numbers.split(" ");

var array2=[];

for(var i=0;i<array.length;i++)

{

if( array[i]!="") array2.push(array[i]);

}

// store the total in an variable and then divide it by the number of

// elements, to get the average.

var total = 0.0;

for(var i=0;i<array2.length;i++)

    {

    total = total + parseInt(array2[i]);

    }

var average = total/array2.length;

// show that result in the text box.

document.getElementById("ans3").value = (average.toString());

}

function readSort()

{

     var x=document.getElementById("numbers");

var numbers=x.value.trim();

var array=numbers.split(" ");

var array2=[];

for(var i=0;i<array.length;i++)

{

if( array[i]!="") array2.push(array[i]);

}

var y=array2.sort(function (a,b){return a-b;});

document.getElementById("ans4").value = (y.toString());

}

function readClear()

{

document.getElementById("numbers").value = "";

document.getElementById("ans1").value = "";

document.getElementById("ans2").value = "";

document.getElementById("ans3").value = "";

document.getElementById("ans4").value = "";

}

</script>

</head>

<body>

<form>

<div class="title"><label>EXAM01_01</label></div>

<p style="clear:both;" />

<div style="float:left;width:150px;"><label>Enter Numbers:</label></div><div style="float:left;"><input type="text" id="numbers" /></div>

<p style="clear:both;" />

<div style="float:left;width:150px;"><label>Sorted List:</label></div><div style="float:left;"><input type="text" id="ans4" /></div>

<p style="clear:both;" />

<div style="float:left;width:150px;"><label>Lowest:</label></div><div style="float:left;"><input type="text" id="ans1" /></div>

<p style="clear:both;" />

<div style="float:left;width:150px;"><label>Highest:</label></div><div style="float:left;"><input type="text" id="ans2" /></div>

<p style="clear:both;" />

<div style="float:left;width:150px;"><label>Average:</label></div><div style="float:left;"><input type="text" id="ans3" /></div>

<p style="clear:both;" />

<div style="text-align:center;">

<input type="button" value="Lowest" onclick="readLowest();" />

<input type="button" value="Highest" onclick="readHighest();"/>

<input type="button" value="Average" onclick="readAverage();"/>

<input type="button" value="Sort" onclick="readSort()"/>

<input type="button" value="Clear" onclick="readClear();"/>

</div>

</form>

</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
How to write a Javascript application using code below that reads names separated by spaces and...
How to write a Javascript application using code below that reads names separated by spaces and for output lists the names with the first letter of every name converted to uppercase and the rest to lower case making sure to sort the output list. <!DOCTYPE> <html> <head> <title>EXAM01_02</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,#names{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> </head> <body>    <form>    <div class="title"><label>EXAM01_02</label></div>    <p style="clear:both;" />    <div style="float:left;width:150px;"><label>Enter...
HTML and Java script Is there a way to delete an element of an array? For...
HTML and Java script Is there a way to delete an element of an array? For example when I click this first button then a random word will appear then when I click this second button then the randomized word will be deleted or removed from the array. here is the portion of the code <button class="wew" onclick="thesisFinal()"><i class="fa fa-play-circle"> Start</i></button></div>              <button class="wew" onclick="removeThesis()"><i class="fa fa-play-circle"> Start</i></button></div>              <p id="thesisget">Click to generate</p>           ...
Java Script I need the code to produce these 3 output. I can only get it...
Java Script I need the code to produce these 3 output. I can only get it to produce input #3 I need it to produce the following: // Input #1: // http://www.example.com // Output // http://www.example.com // Input #2: // http://www.example.com?name=r2d2 // Output // http://www.example.com // name: r2d2 // Input #3: // http://www.example.com?name=r2d2&email=r2d2%40me.com&human=no // Output // http://www.example.com // name: r2d2 // email: [email protected] // human: no THIS IS WHAT I HAVE SO FAR: HTML <!DOCTYPE html> <html lang="en"> <head> <meta...
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...
I have created images that I would like to have placed where the message is revealed?...
I have created images that I would like to have placed where the message is revealed? What is the best way to make it work. I tried to make it work and have not had much success. My images are saved as png's. Here is my original code. <!Doctype html> <html> <head> <meta charset="UTF-8"> <title>Dice Game</title> <link rel="stylesheet" type="text/css" href="demo.css"> </head> <body> <div class="row" align="center"> <div class="col-4"> <h3>Your Dice</h3> <img src="images/d1.png" width="100" height="100" alt="roll: 1" id="mydice1"> <img src="images/d1.png" width="100" height="100"...
Examine the following code, which contains six common bugs. In a separate Microsoft Word (or other...
Examine the following code, which contains six common bugs. In a separate Microsoft Word (or other word processing or text file), identify the line number of at least three (3) bugs as well as a brief description of each bug. 1. 2. 1. <!DOCTYPE html> 2. </html> 3. <head> <link rel="stylesheet" href="MyStyle.css"> </head> 4. <body> 5. <nav> 6. <a href="GroceryHome.html">Home</a> | 7. <a href="Products.html">Products</a> | 8. <a href="AboutUs.html">About Us</a> | 9. <a href="Contact.html">Contact</a> 10. </nav> 11. <header> 12. <h1> My...
I am trying to make a contact form to give input on another browser window. I...
I am trying to make a contact form to give input on another browser window. I am only getting the php code. I am trying to figure out why it won't post. Her is my html and php files: <!DOCTYPE html> <html> <head> <title>Contact</title> <link rel="stylesheet" href="main.css"> </head> <body>    <h1>Contact Form</h1> <nav> <ul> <li><a href="index.html">Home</a></li> <li><a href="page2.html">My PodCast</a></li> <li><a href="page3.html">Contact Me</a></li> <li><a href="page4.html">Resources</a></li> <li><a href="addressbook.html">Address Book</a></li> <li>Contact Form</li> </ul> </nav> <center><h2>Please fill out form</h2> <div id='container'> <div id='header'></div> <center><h3>Contact</h3>...
In the previous assessment, you used a static set of named variables to store the data...
In the previous assessment, you used a static set of named variables to store the data that was entered in a form to be output in a message. For this assessment, you will use the invitation.html file that you modified in the previous assessment to create a more effective process for entering information and creating invitations for volunteers. Rather than having to enter each volunteer and create an invitation one at a time, you will create a script that will...
<?php    if(isset($_GET['submit'])){ //sanitize the input        /* Check the error from the input: if...
<?php    if(isset($_GET['submit'])){ //sanitize the input        /* Check the error from the input: if input from user is empty -> get an error string variable if input is not empty -> use preg_match() to match the pattern $pattern = "/^[1-9][0-9]{2}(\.|\-)[0-9]{3}(\.|\-)[0-9]{4}$/"; -> if it's a matched, get a success string variable */           } ?> <!doctype html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <!-- Bootstrap CSS --> <link...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT