1

So I am starting my first ever personal coding project and I decided to create a website that will pick a restaurant nearby from a list randomly.

I am in the process of learning JS at the moment and I was just wondering what would be the best way to go about it.

I will have about 40-50 checkboxes on the website and users will be able to select which restaurants they may want to eat at and then click a button and one will be picked at random.

Is there a way to assign them all to an array and then pick one from the array at random?

Sorry if my question is too broad, I really don't know what specifically I am asking for.

Daniel Miller
  • 57
  • 1
  • 1
  • 10

2 Answers2

0

Use Random Generation number Function by that number select through index from array or list what ever

  • While I agree this is the way to go, I'd be remiss not to remark that "what ever" (at least to me) signals a certain disdain for the question author. We've all been at this point at the start of our careers, and while this question may seem trivial to you and me, it nonetheless deserves a more thoughtful answer than the one you provided. – Nelewout Jul 12 '17 at 09:06
0

You can use document.createElement() to dynamically create checkbox elements in your JS. Add those elements to an array, once the user executes an action where you want to randomly select a checked box, traverse array for all checked items and use Math.random() to select a random value from the set of checked boxes.

httpNick
  • 2,524
  • 1
  • 22
  • 34