How to get a single line per string in the Javascript loop

advertisements

I am currently playing with javascript and trying to get the hang of it. I was wondering how to get each greeting in one line rather than one after the other after the other. Hope my question makes sense.

window.onload = function() {
getGreeting();
};

for(var hours=0; hours < 24; hours++)
{

document.getElementById("loop").innerHTML = document.getElementById("loop").innerHTML + "\n" +  getGreeting(hours);
}

function getGreeting(hours) {
    var greetingText;
    if (hours >=6 && hours < 12) {
        greetingText = "Good morning!";
    } else if (hours >= 12 && hours < 17) {
        greetingText = "Good afternoon!";
    } else if (hours >= 17 && hours < 23) {
        greetingText = "Good Evening!";
    } else if (hours >= 23 || hours < 6) {
        greetingText = "Go to sleep!";
    }
    return greetingText;
}

http://jsfiddle.net/priswiz/KcS5b/ you see in the jsfiddle file that the greetings are lined up one after the other, I would like to know how to get one per line.

Thanks!


Replace the \n with <br />

http://jsfiddle.net/KcS5b/2/