Game seven and a half JS

0

I'm doing the seven-and-a-half game in JS, for the moment I'm trying to show on the screen when I press a button a random card and its punctuation, that is, the number one will be worth 1 point, the number 2 2 points, so succesivamente, I need a little enough of help. Thanks in advance

 <!doctype html>
<html>
<head>
</head>
<body>
<form>
<img src="baralla/reverso.png" name="carteta">
<p>
<div id="puntuacio"> Punts </div>
<button onClick="donar();"> Tirar carta </button>
</body>
<html>

<script type="text/javascript">
function donar() {
    var numeros=48;
    var rand= Math.random();
    var rand1 = Math.round( (numeros-1)* rand) +1;
    var setimedio=new Array(47);
    /* Bastos */
    setimedio[0]="baralla/basto/1.png";
    setimedio[1]="baralla/basto/2.png";
    setimedio[2]="baralla/basto/3.png";
    setimedio[3]="baralla/basto/4.png";
    setimedio[4]="baralla/basto/5.png";
    setimedio[5]="baralla/basto/6.png";
    setimedio[6]="baralla/basto/7.png";
    setimedio[7]="baralla/basto/10.png";
    setimedio[8]="baralla/basto/11.png";
    setimedio[9]="baralla/basto/12.png";

    /* Copas */
    setimedio[10]="baralla/copa/1.png";
    setimedio[11]="baralla/basto/2.png";
    setimedio[12]="baralla/basto/3.png";
    setimedio[13]="baralla/basto/4.png";
    setimedio[14]="baralla/basto/5.png";
    setimedio[15]="baralla/basto/6.png";
    setimedio[16]="baralla/basto/7.png";
    setimedio[17]="baralla/basto/10.png";
    setimedio[18]="baralla/basto/11.png";
    setimedio[19]="baralla/basto/12.png";

    /* Oros */
    setimedio[20]= "baralla/oro/1.png";
    setimedio[21]= "baralla/oro/2.png";
    setimedio[22]= "baralla/oro/3.png";
    setimedio[23]= "baralla/oro/4.png";
    setimedio[24]= "baralla/oro/5.png";
    setimedio[25]= "baralla/oro/6.png";
    setimedio[26]= "baralla/oro/7.png";
    setimedio[27]= "baralla/oro/10.png";
    setimedio[28]= "baralla/oro/11.png";
    setimedio[29]= "baralla/oro/12.png";

    /* Espadas */

    setimedio[30]= "baralla/espada/1.png";
    setimedio[31]= "baralla/espada/2.png";
    setimedio[32]= "baralla/espada/3.png";
    setimedio[33]= "baralla/espada/4.png";
    setimedio[34]= "baralla/espada/5.png";
    setimedio[35]= "baralla/espada/6.png";
    setimedio[36]= "baralla/espada/7.png";
    setimedio[37]= "baralla/espada/10.png";
    setimedio[38]= "baralla/espada/11.png";
    setimedio[39]= "baralla/espada/12.png";
    document.carteta.src = setimedio;

}

</script>
    
asked by Archeon El Centinela 10.11.2017 в 19:12
source

1 answer

1

You can, more easily and orderly generate your letters like this

function gen() {
var arr = [], max = 20, static = "baralla/basto/carta";
for(let i =1;i<=max;i++){
 arr.push(static+i+".png");
}
return arr;
}

function azar() {
 var all = gen(),
     random = Math.floor(Math.random() * all.length);
     return all[random];
}

console.log('Carta al azar: ${azar()}');
    
answered by 10.11.2017 / 22:11
source