JSFiddle - React, Tailwind, and code Playground

Write a code to sort 3 variables

by Porfirio Chavez

HTML

<input type="text" value="7" id="a" maxlength="1">
<input type="text" value="1" id="b" maxlength="1">
<input type="text" value="5" id="c" maxlength="1">
<br>
<button type="button" onclick="ordenarNumeros()">
Ordenar
</button>
</button>
<hr>
<input type="text" id="result" readonly>

JavaScript

function ordenar(a,b,c){
	if(a <= b && a <= c){
  	//a
    if(b <= c){
    	//a - b - c
      return [a,b,c];
    } else {
    	// a - c - b
      return [a,c,b];
    }
  } else if(b <= a && b <= c){
  	//b
    if(a <= c){
    	//b - a - c
      return [b,a,c];
    } else {
    	//b - c - a
      return [b,c,a];
    }
  } else if(c <= a && c <= b){
    //c
    if(a < b){
      //c - a - b
      return [c,a,b];
    } else {
      //c - b - a
      return [c,b,a];
    }
  }
}

function ordenarNumeros(){
  var a = document.getElementById('a').value;
  var b = document.getElementById('b').value;
  var c = document.getElementById('c').value;
  
  var result = document.getElementById('result');
  result.value = ordenar(a,b,c);
}
//alert(ordenar(7,1,5));