Our aim is to randomly display a text string from a set. It involves the following steps
var text_st = new Array("String1", "String2", "String3", "String4", "String5", "String6", "String7", "String8", "String9", "String10"); var l = text_st.length; var rnd_no = Math.floor(l*Math.random()); alert(text_st[rnd_no]);
Note: Array are zero-indexed, thus, we can use the value of variable l (length of the array) directly because we are using floor() to round down to an integer.
I have used this code on several web sites to display a random testimonial from a set. So each time the web page loads a testimonial is selected and displayed at random. The code can also be used to display a random quote or a greeting.
Wingdings included since Windows 3.1 has been the center of a strange controversy. The dingbat font contains many popular and common shapes that can quickly be incorporated in documents. In the original font, typing the three letters 'NYC' in sequence, would display skull-cross bones, star of David and thumbs up sign. Some people interpreted as an antisemitic message and raised a big hue and cry over it. In later versions, the symbols were changed to eye, heart and skyline, which is like a hat tip to the famous "I ♥ NY" logo designed by Milton Glaser. [more...]