Saturday, March 3, 2018

sorting the values

 To write a Javascript program to define a user defined function for sorting the values in an array. Use HTML5 for user interface.

<!DOCTYPE html>
<html>
<body>

<p>Click the button to sort the array.</p>

<button onclick="myFunction()">sort</button>

<p id="demo"></p>

<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {
    fruits.sort();
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>

</html>

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home