Display every hour another content

With a timer. This will refresh the phrase every second.

setInterval(function() {
    h = new Date().getHours(); //Get the current hour

    phrase = new Array(); //Create an array of phrases
    phrase[1] = 'Hello';
    phrase[2] = 'there';
    phrase[3] = 'this';
    phrase[4] = 'will';
    phrase[5] = 'show';
    phrase[6] = 'a';
    phrase[7] = 'different';
    phrase[8] = 'message';
    phrase[9] = 'depending';
    phrase[10] = 'on';
    phrase[11] = 'the';
    phrase[12] = 'hour';
    phrase[13] = 'of';
    phrase[14] = 'day';
    phrase[15] = 'that';
    phrase[16] = 'you';
    phrase[17] = 'look';
    phrase[18] = 'at';
    phrase[19] = 'it';
    phrase[20] = '!';
    phrase[21] = 'W';
    phrase[22] = 'X';
    phrase[23] = 'Y';
    phrase[24] = 'Z';

    document.getElementById('placeHolder').innerHTML = phrase[h-1]; //Show the array item relevant to the hour
}, 1000);

Leave a Comment