-4

i am trying to have something like:

category = ("word1","word2","word3")
       ("definition1","definition2","definition3");
category1 = ("word1","word2","word3")
       ("definition1","definition2","definition3");

the basic goal is to select and output (lets just say 3) random words from any random category and be able to call on their relevant data as i develop it more (the category name and the definition of the word that was chosen randomly).

i also don't want duplicates, and i appreciate all suggestions! :) thanks a lot!

  • Are you trying to create arrays here? Because if so you want `[` and `]` instead of parentheses... – Elliot Bonneville May 08 '13 at 15:36
  • I'm way too lazy atm: http://stackoverflow.com/questions/4550505/getting-random-value-from-an-array. Oh and if you're asking yourself, since both array elements are in correct order you can select the word and corresponding definition with the same index... – Simon May 08 '13 at 15:39

1 Answers1

3

You want a structure that is an array of objects:

category1 = [
    { word: "word1", definition: "def1" },
    { word: "word2", definition: "def2" },
    { word: "word3", definition: "def3" }
];

Then, to select a value from category1, pick some category1[i] at random and use category1[i].word and category1[i].definition.

You can extend each object to have additional properties later as needed (numberOfSylables, gradeLevel, etc.)

apsillers
  • 112,806
  • 17
  • 235
  • 239