How can I make the following to display randomly? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How can I make the following to display randomly?

function displayResult() { document.getElementById("choices").rows[0].cells[0].innerHTML="<img src='images/image1.png'/>"; document.getElementById("choices").rows[0].cells[1].innerHTML="<img src='images/image2.png'/>"; document.getElementById("choices").rows[0].cells[2].innerHTML="<img src='images/image3.png'/>"; document.getElementById("choices").rows[0].cells[3].innerHTML="<img src='images/image4.png'/>"; document.getElementById("choices").rows[0].cells[4].innerHTML="<img src='images/image5.png'/>"; }

24th Feb 2020, 9:55 AM
SWL
2 Answers
+ 1
SWL I'm new with JS but to easily get help, you have to like your attempted code. Please link your code.
24th Feb 2020, 10:27 AM
JS LOVER
JS LOVER - avatar
+ 1
SWL you should create an array with picture numbers, use Math.random() function to randomized the picture image, and splice the item out from the array, to update the cell. https://code.sololearn.com/W0oipIIzNl8e/?ref=app
24th Feb 2020, 2:25 PM
Calviղ
Calviղ - avatar