lundi 23 août 2021

Javascript random object inside a random object

Hello i ve been searching for how to get to an object randomly but i need to get another random object that is inside the first random.

This is a card game i want to try.

To be clear my objects are 4 in wich each one they have 10 other objects. I need to get first a random one and with that object get the randoms inside. It needs to be the ones on the selected one because each of them have different values.

i have this

var palos= {
    espada: {
        uno:70, dos:45, tres:50, cuatro:5, cinco:10, seis:15, siete:60, diez:25, once:30, doce:35
    },
    basto: {
        uno:65, dos:45, tres:50, cuatro:5, cinco:10, seis:15, siete:20, diez:25, once:30, doce:35
    },
    Oro: {
        uno:40, dos:45, tres:50, cuatro:5, cinco:10, seis:15, siete:55, diez:25, once:30, doce:35
    },
    copa: {
        uno:40, dos:45, tres:50, cuatro:5, cinco:10, seis:15, siete:20, diez:25, once:30, doce:35
    },
    
}

var palosdados = Object.keys(palos)[Math.floor(Math.random()*Object.keys(palos).length)];
console.log(palosdados);

Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire