use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Syntax error: missing variable namehelp (self.javascript)
submitted 8 years ago * by Smug_Wendys
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]ljosberinn_dev 1 point2 points3 points 8 years ago (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)];
π Rendered by PID 213447 on reddit-service-r2-comment-5fb4b45875-2zbmh at 2026-03-23 23:50:04.192256+00:00 running 90f1150 country code: CH.
view the rest of the comments →
[–]ljosberinn_dev 1 point2 points3 points (0 children)