Please login to start chat

ICT Solutions 14 Jun 2022, 20:59:37
Category : JavaScript Tutorials

Sort number randomly (JS Array Sort)

<!DOCTYPE html>
<html>
<head>
<title>JavaScript Code Testing</title>
</head>
<body>
<p id = "demo"></p>
<button type = "button" onclick = "jsRandom()">Sort Now</button>
<script>
var numbers = [300, 40, 83, 49, 92, 200, 79];
document.getElementById("demo").innerHTML = numbers.join("<br />");

function jsRandom(){
var random = numbers.sort(function(a, b){return 0.5 - Math.random();});
document.getElementById("demo").innerHTML = random.join("<br />");
}
</script>
</body>
</html>

Comments:

No comment to show.

Available Services
Download Android Application