javascript - I have an error and for some reason the numbers are being changed and not the names? -


this question need on.

i need have names change randomly. need names same both selection.

if notice, possible have 2 random names same. made error , need fix first , second names unique. wanted pass first name generated getoption function of second name second name cannot name. having trouble can please me?

so far have code make numbers change i'm not sure how randomize names

 function getrandomnumber(min, max, notin) {     return min + math.floor((max - min + 1) * math.random())   }     function getoption(s, ch, num) {     var = s.split(ch);     return a[num - 1];   }     var marymoney = getrandomnumber(50, 100, "");   var johnmoney = getrandomnumber(50, 100, "");   var maryitem = getrandomnumber(5, 20, "");   var johnitem = getrandomnumber(5, 20, "");   var marystuff = getoption("notebook,pencil,ruler,pen,eraser,binder,backpack", ",", getrandomnumber(1, 7));   var johnstuff = getoption("notebook,pencil,ruler,pen,eraser,binder,backpack", ",", getrandomnumber(1, 7));   var totalleft = marymoney + johnmoney - maryitem - johnitem;   var str = "mary had $" + marymoney + " , john had $" + johnmoney + ".          mary buys " + marystuff + " $" + maryitem + " , john buys " + +"            $" + johnitem + ". have $" + totalleft + ".";     document.write(str);

try this, works me:

function getrandomnumber(min, max, notin) {      return min + math.floor((max - min + 1) * math.random())  }    function getoptions(s, ch) {      var = s.split(ch);      a.sort( function() { return 0.5 - math.random() } );        return a;  }    var marymoney = getrandomnumber(50, 100, "");  var johnmoney = getrandomnumber(50, 100, "");    var maryitem = getrandomnumber(5, 20, "");  var johnitem = getrandomnumber(5, 20, "");    var stuff = "notebook,pencil,ruler,pen,eraser,binder,backpack";  var options = getoptions(stuff, ',');    var marystuff = options[0];  var johnstuff = options[1];    var totalleft = marymoney + johnmoney - maryitem - johnitem;    var str = "mary had $" + marymoney + " , john had $" + johnmoney +          ".          mary buys " + marystuff + " $" + maryitem +          " , john buys " + johnstuff + "            $" + johnitem +          ". have $" + totalleft + ".";    document.write(str);


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -