Javascript – Random Text Rotator

Single statement loader, the simplest way:

<!DOCTYPE html>
<html>                                                                 
<head>
 
</head>
  
<body>

RANDOM TEXT ROTATOR<br>
Reload the page to change statement<br>

<script language="JavaScript">
// Random variable from 0 to 14
// Math.random() return a value between 0 and 1
// Math.floor() function returns the largest integer less than or equal to a number
var ran = Math.floor(15 * Math.random()); 

// Array of images START
mytext = new Array()
mytext[0] = 'Statement 0';
mytext[1] = 'Statement 1';
mytext[2] = 'Statement 2';
mytext[3] = 'Statement 3';
mytext[4] = 'Statement 4';
mytext[5] = 'Statement 5';
mytext[6] = 'Statement 6';
mytext[7] = 'Statement 7';
mytext[8] = 'Statement 8';
mytext[9] = 'Statement 9';
mytext[10] = 'Statement 10';
mytext[11] = 'Statement 11';
mytext[12] = 'Statement 12';
mytext[13] = 'Statement 13';
mytext[14] = 'Statement 14';
// Array of images END

// Write the random variable
document.write('The random image is the number: ' + ran + '<br>');
// Write the image, the result must be: <img src="css/images-gimme-code-2013-0038/image3.jpg">
document.write(mytext[ran] + '<br>');
</script>

</body>
  
</html>
DEMO

 

My official WebSite >