We are discussing the use of CSS and Javascript in this project.
I am looking to have 10 unique CSS div's appear randomly on the screen after a time delay of 1-3 seconds each. These div's will consist of a yellow square, green square, red square, and more.
Issue:
- Selecting one out of 10 (or N) objects at random: Do I need to rely solely on the Math.random() method, such as using if between 0 and 0.1 select the first object, if between 0.1 and 0.2 choose the second object, etc., or is there a better way to make this process more scalable?
Edit: It seems that I did not explain the issue clearly. I understand that Math.random() can be used for this task, but manually writing conditions for selecting from 10 (or N) elements may not be ideal. How can I instruct the computer to pick one element out of 10 (or N)? The most helpful response came from dystroy - suggesting to shuffle an array and then select the first element. Thank you!