dimanche 6 novembre 2016

Math.random not returning the right value

So, I'm wondering what I'm doing wrong here? It's giving me numbers like 3. (I'm passing the variable a as "7-10")

function getDmg(a, y) { var s = Math.floor((Math.random() * (a.split('-')[1])) + (a.split('-')[0])); if(y == true) { console.log('You dealt ' + s + ' damage.'); } else { console.log('You took ' + s + ' damage.'); } return s; // Giving numbers like 3...? }




Aucun commentaire:

Enregistrer un commentaire