<form onSubmit="return sort(this)">
Enter any three numbers: <br>
<input type="text" name="first" size=5><br>
<input type="text" name="second"size=5><br>
<input type="text" name="third" size=5><br>
<input type="submit" value= "Rank the numbers!" onClick = "sort(this.form)">
</form>
JavaScript
function sort(form) {
var a1 = form.first.value
var b1 = form.second.value
var c1 = form.third.value
var a2 = parseFloat(a1)
var b2 = parseFloat(b1)
var c2 = parseFloat(c1)
var rank_the_numbers = [a2, b2, c2]
rank_the_numbers.sort(function (a, b) {
return b - a
})
console.log("The largest number is: " + rank_the_numbers[0])
console.log("<br> The second largest number is: " + rank_the_numbers[1])
console.log("<br> The smallest number is: " + rank_the_numbers[2])
console.log(rank_the_numbers);
return false;
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.