mercredi 7 juin 2017

An easy if-statement

So there is probably a really easy solution to this, but I'm trying to get a message in a P when two players are inputted.. So far I've got this(some norwegian words there, sorry):

var spillere = [];

function myFunction() {
if(spillere.length > 0) {
 document.getElementById("printAppear").innerHTML = '<button onclick="Printresultat()">Print resultat</button>';
 }
if(spillere.length < 2) {
    var player_navn = document.getElementById('navn').value;
    var player_poeng = document.getElementById('poeng').value;
    spillere.push([player_navn, parseFloat(player_poeng)]);

    spillere.sort(function(a,b){ 
        return a[1] - b[1];
    });


    document.getElementById("demo").innerHTML = "";
    for(i = 0; i < spillere.length; i++) {
        document.getElementById("demo").innerHTML += (i+1) + ". " + spillere[i][0] + " - " + spillere[i][1] + " poeng<br />"; 
    }

}

So I'm basically just wanting to get a text where it says "Congratulations" and then the name of the player who won in this:

<p id="vinner"></p>

spillere=players and vinner=winner

Hope you understand what I'm trying to do

Aucun commentaire:

Enregistrer un commentaire