+ 1

Weekend Challenge: Randomly put array elements in containers [JavaScript]

You have: --> 4 HTML divs; --> an array like this ["solo", "learn", "coding", "future"]. Make a program that: => puts each word in one of the div elements randomly; => add the class "special" to the div that contains it.

16th Dec 2017, 12:56 PM
Ledio Deda
Ledio Deda - avatar
3 Respostas
+ 6
what do you mean mark as special? do you mean <mark></mark>?
16th Dec 2017, 1:37 PM
EnRico Lam
EnRico Lam - avatar
+ 4
var a= "<div>"; var b= "</div><div>"; var c= "</div>"; function shuffle(arra1) { var ctr = arra1.length, temp, index; while (ctr > 0) { index = Math.floor(Math.random() * ctr); ctr--; temp = arra1[ctr]; arra1[ctr] = arra1[index]; arra1[index] = temp; } return arra1; } var myArray = ["solo", "learn", "coding", "future"]; var seq=shuffle(myArray); document.write(a+seq[0]+b+seq[1]+b+seq[2]+b+seq[3]+c); var where= seq.indexOf("future"); var tar=document.getElementsByTagName("div")[where]; tar.className="special";
16th Dec 2017, 3:35 PM
EnRico Lam
EnRico Lam - avatar
+ 2
No not at all...It's my fault, I wasnt clear... Now you get it??
16th Dec 2017, 1:53 PM
Ledio Deda
Ledio Deda - avatar