0
Good morning guys.
I have this code, and I need his output to go backwards, I’ll put an image just to illustrate.
code:
<script>
var num =[];
function loadDoc() {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      tratarNumero(this);
    }
  };
  xhttp.open("GET", "http://stutz.000webhostapp.com/php/sorteio.php", true);
  if (num.length < 15){
     xhttp.send();
  }else{
    document.getElementById("sorteio").innerHTML += "<br> Fim do sorteio - Máximo de 15 números.";
  }
  
}
function tratarNumero(response) {
  var sorteado = response.responseText;
  console.log (response.responseText);
  var unico = true;
  for( var n of num){
    if (n == sorteado){
		unico = false;
	}
  }
  if (unico){
    num.push(sorteado);
   var comprimento = num.length;
   var valor = comprimento.toString().split(",");
   var invertido = valor.reverse().join("");
	 document.getElementById("sorteio").innerHTML += "<br>" + invertido + "º Número sorteado:" + sorteado;
	 var table = "<tr>";
	 for( var n of num){
		table += "<td>" + n + "</td>";
	 }
	 table += "</tr>";
	 document.getElementById("numeros").innerHTML = table;
	 
  }else{
      document.getElementById("sorteio").innerHTML += "<br> Número sorteado:" + invertido +"(repetido)";
  }
}
</script><style>
table,th,td {
  border : 1px solid black;
  border-collapse: collapse;
}
th,td {
  padding: 5px;
}
</style><!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
</head>
<body>
<h2>Loteria AJAX</h2>
<br><button type="button" onclick="loadDoc()">Sortear</button>
<br><br>
Resultado:
<br>
<table id="numeros"></table>
<br>
Status do sorteio:
<p id="sorteio"></p>
</body>
</html>the way out is like this
I need you to stay like this


Cara pq you are using a table to print a listing? Pq does not use a UL/LI ?
– hugocsl
because this is a continuation of a job and I need it to stay the way it is
– user126232
If it was a list you could use Flex and column-Reverse to invert the order with CSS, but with table I wouldn’t tell you to change the table display to flex
– hugocsl