I’m pretty new to JS but I want to make a very basic RPG item generator that is controlled by probability. This is what I have come up with.
I have a problem with the itemtype part. After the probability roll is done for itemtype, I want to randomly generate a group of elements under weapons, accessories, and armors.
It should be something like Rare Sword, Uncommon staff, Common gloves, or Common Chest.
How do I go about this?
var rarityNum = Math.floor( 1 + Math.random() * 100 );
var itemNum = Math.floor( 1 + Math.random() * 100 );
var rarity;
if ( rarityNum > 75 ) { rarity = "rare "; }
else if ( rarityNum > 65 ) { rarity = "uncommon "; }
else { rarity = "common "; }
var weapons =["sword","bow","staff"];
var armors =["chest","leggings","gloves"];
var itemtype;
if ( itemNum > 51 ) { itemtype = "weapons"; }
else if ( itemNum > 40 ) { itemtype = "accessories"; }
else { itemtype = "armors"; }
document.write (rarity);
document.write (itemtype);
1 Answer