R
R
Roman Progressive2018-10-26 06:16:27
JavaScript
Roman Progressive, 2018-10-26 06:16:27

How can this JS be templated?

How can this JS be templated?

var h=(new Date()).getHours();
            if (h > 3 && h <  12) document.writeln("Доброе утро, {login}!");
            if (h > 11 && h <  18) document.writeln("Добрый день, {login}!");
            if (h > 17 && h <  24) document. writeln("Добрый вечер, {login}!");
            if (h > 23 || h <  4 ) document. writeln("{login}, почему не спишь?");

I need it to be like this:
var h=(new Date()).getHours();
            if (h > 3 && h <  12) document.writeln("<h4>Доброе утро, <div class="login-name">{login}</div>!</h4>");
            if (h > 11 && h <  18) document.writeln("<h4>Добрый день, <div class="login-name">{login}</div>!</h4>");
            if (h > 17 && h <  24) document. writeln("<h4>Добрый вечер, <div class="login-name">{login}</div>!</h4>");
            if (h > 23 || h <  4 ) document. writeln("<h4><div class="login-name">{login}</div>, почему не спишь?</h4>");

Well, after templating, JS is not displayed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dies Irae, 2018-10-26
@Pro-gressive

You have double quotes closing in the middle. Either escape characters, or like this:
"asd 'dsa'"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question