javascript how to sort variables by user input code example
Example: javascript how to sort variables by user input
<!DOCTYPE html>
<html>
<body>
<p>Type x, y, zand click "Sort" to get them sorted</p>
<button onclick="sort()">sort</button>
<p id="answer"></p>
<script>
var x = window.prompt("x=?");
var y = window.prompt("y=?");
var z = window.prompt("z=?");
var zmienne = [x,y,z];
document.getElementById("answer").innerHTML = zmienne;
function sortuj() {
zmienne.sort();
document.getElementById("answer").innerHTML = zmienne;
}
</script>
</body>
</html>