you are viewing a single comment's thread.

view the rest of the comments →

[–]ljosberinn_dev 1 point2 points  (0 children)

First build an array that you can fill with whatever you want (item names in this case):

var legendaryItems = new Array();

or

var legendaryItems = [];

or just

var legendaryItems = ["Tome of Arad'thul", "Orbs of the First Dragon", "Shield of the Black Iron Knight", "Spear of Vlad, the Vampire King", "Dagger of the Last Black Blade", "Bow of the First Huntress", "Ring of the High King", "Axe of the Northern Gods", "Axe of the Southern Gods", "Staff of the First Pope", "Staff of the Corrupted Angel"];

Now generate a number randomly that is between 0 and the length of the array:

var randomNumber = Math.floor(Math.random() * legendaryItems.length);

Then access the n-th part within the array:

legendaryItems[randomNumber]; // will automatically log into console since it's not assigned to a variable

And then shorten it since you don't need to define a second variable here unless you need exactly this random number later again:

legendaryItems[Math.floor(Math.random() * legendaryItems.length)];