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
Post a Comment