HTML and Javascript - How do we make an onclick button for a random list item? | SoloLearn: Learn to code for FREE!

+11

HTML and Javascript - How do we make an onclick button for a random list item?

I'd like to make a random button like this: https://code.sololearn.com/WpDt913j6V8m/#html The only difference is that I'd like it to display a random HTML list item instead of a random string in the array. What I have down so far: https://code.sololearn.com/Ws7tzq1v95TY/#html I think it's necessary to associate the collection of <li> with items in a JavaScript array. I've struggled much on aggregating this concept and that of random selection into code.

9/29/2020 8:16:01 AM

Solus

6 Answers

New Answer

+6

something like this? you can use object. https://code.sololearn.com/W51GwZQtHzyr/?ref=app

+5

I edited the code to show you how you can do that. If you want to add more items like performed by and other then add more properties to object in array.

+5

You don't have to worry about that. Just write your css and when you dynamically add tag to your HTML it will be applied. I again edited the code and added css demo. P.s. level 17 does not have to do anything with skills. :)

+4

RDC WOW. Your code is so organized... You're a real master. That's a level 17 for you haha. There's just one problem. It seems like most of the things now have migrated over to Javascript. As for CSS, how are we supposed to apply styling techniques to the texts and headings if none exist in HTML?

+4

Got it. Thank you for ending my month-long struggle. P.s. It must have something to do with your name then... RDC = Real-Deal Coder >=]

+2

RDC How will your JS portion allow us to include various nested tags within the list item? For instance, the <iframe> and <a href> inside the list items? Reference: https://code.sololearn.com/Ws7tzq1v95TY/#html