Jump to content

Random Variables


Darkness

Recommended Posts

Ah, how would you set the variable, though?I tried
var Variable= "(Math.floor(Math.random()*3)";

That won't work, however. I need the variable, Variable, to be a random number between one and three.

No, that won't work. When you use quotes you are using a string. You are saying that the variable Variable contains the string "(Math.floor(Math.random()*3)" instead of the result of that code getting executed. Anytime you put anything in quotes, you are using a literal value, not an operation.var num = Math.floor((Math.random() * 2) + 1);
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...