0
Is it possible to pick a random variable in JavaScript?
Selecting a random variable using a method or function?
8 ответов
+ 3
function random_item(items)
{
return items[Math.floor(Math.random()*items.length)];
}
var items = [paul, Sarah, Peter];
console.log(random_item(items));
+ 1
Yea of course!
+ 1
Gulshat Taganova how?
Can you write short code as an example or send a link to a page that tell me how to do it🙏
+ 1
Gulshat Taganova I know about this, I meant a function that selects a variable you've set randomly, some thing like this:
var nameOne = "paul";
var nameTwo = "Sarah";
var nameThree = "Peter";
If I want to select a random variable from the three variables how do I do it?
+ 1
Gulshat Taganova thanks a lot
+ 1
Never mind
0
Math.random();
Ex:Math.floor((Math.random() * 10) + 1);
It returns random number between 1 and 10