Invert Ocorrecias

0

Good morning guys.

With this code, and I need the output of it to go the other way, I will 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 output is so

Ineedyoutostaythatway

    
asked by anonymous 30.09.2018 / 17:30

0 answers