Math.random returns random values between 0 (inclusive) and 1 (exclusive). To get a number from 7 to 10, you'll need to specify the max value, subtract the min and then ADD your min value to the result:
This adjusted code returns random damages in your range. Remember: if you do want to possibly get a max of 10, you need to pass 11 as the upper value for Math.random
because the upper value is exclusive:
function getDmg(a, y) {
var min = parseInt(a.split('-')[0],10);
var max = parseInt(a.split('-')[1],10);
var s = Math.floor(Math.random() * (max - min) + min);
if(y == true) {
console.log('You dealt ' + s + ' damage.');
} else {
console.log('You took ' + s + ' damage.');
}
return s; // Giving numbers like 3...?
}
getDmg("7-11", true);
getDmg("7-11", false);
See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/random for more details on Math.random()