Jump to content

Random Variables


Darkness
 Share

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...