sort() and reverse() methods in javascript

sort() and reverse() methods in javascript




<!DOCTYPE html>
<html>
<head>
<title>JAVASCRIPT</title>
<script type="text/javascript">
var inp = new Array(5);
for(var i=0;i<5;i++)
{
inp[i]= prompt("PLEASE ENTER ANY 5 VALUES");
}
document.write("<b><u>VALUES ENTERED BY YOU ARE AS FOLLOWS</b></u><br><br><br>");
for(var j=0;j<5;j++)
{
document.write(" " + inp[j]);
}
inp.sort();
document.write("<br><br>");
for(var j=0;j<5;j++)
{
document.write(" " + inp[j]);
}
</script>
</head>
<body >
</body>
</html>



First ask the user to input any 5 values and then sort them using sort() method and display them with a loop. Below is the output and th coding part :






Comments

Popular posts from this blog