mercredi 9 septembre 2015

the "min" part of the min/max isnt working - javascript

So Ive got this script to find a random number between two user-typed in values. The "max" part works, the randomly generated number is never higher than the higher number. But the numbers generated are still from 1 to the highest number, not whatever "min" to set to. What am I doing wrong?

Looking at other codes Ive tried the "(max - min + 1) + min" formula but it gave the exact same result as Im having now. And sometimes it didnt register at all. It may be a simple syntax problem Im missing? Other variations end up with the random generated number concencrated with the value of "min" instead of adding the two number values together. For example, between 10 and 20, Ill roll an 8 and it will display "810" in the answer box, instead of 18 like it should be.

<script>
function roll_the_dice(){

var minA = document.getElementById('hp_one').value;
var maxA = document.getElementById('hp_two').value;
var rangeA = (minA,maxA);
var resultA = Math.floor(Math.random() * rangeA + 1);
document.getElementById('hp_result').value = resultA;
</script>




Aucun commentaire:

Enregistrer un commentaire