I am having a problem with this. I want to pick random word from an array everytime the popup loads. But the word doesn't change. I always get results as:
(march, march, march.. january, january, january, january, january)...
It just pick the random month and then uses it every loop. I want to make it random every loop. Can someone please help me?
var i;
for (i = 0; i < 5; i++) {
$("#notification").fadeIn("slow").delay(1000).fadeOut("slow");
var myArray = ['January', 'February', 'March'];
var rand = myArray[Math.floor(Math.random() * myArray.length)];
document.getElementById("notification").innerHTML = rand;
}
//$("#notification").append(rand);
#notification {
position: fixed;
bottom: 5px;
left: 5px;
width: 170px;
/* set to 100% if space is available */
height: 70px;
z-index: 105;
text-align: center;
font-weight: normal;
font-size: 12px;
color: white;
background-color: #FF7800;
box-shadow: 0 0 10px #222;
padding: 5px;
opacity: 0.7;
filter: alpha(opacity=70);
/* For IE8 and earlier */
}
#notification span.dismiss {
border: 2px solid #FFF;
padding: 0 5px;
cursor: pointer;
float: right;
margin-right: 10px;
}
#notification a {
color: white;
text-decoration: none;
font-weight: bold
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="notification" style="display: none;">
<span class="dismiss"><a title="dismiss this notification">X</a></span>
</div>
JSfiddle link