user466534
user466534

Reputation:

javascript code does not show me expected output

i am writing javascript code on nodepad++,i am at beginner level and write just this code

<html>
<body>
<script type="text/javascript">
var d=new Date();
var time=d.getHours();
if(time<10)
{
document.write("<b> good morning </b>");

}
else
{
document.write ("<b> good afternoon </b>");

}
</script>
</body>
</html>

then from editor nodepad++,i clicked run in google chrome,but got only this

<html>
<body>
<script type="text/javascript">
var d=new Date();
var time=d.getHours();
if(time<10)
{
document.write("<b> good morning </b>");

}
else
{
document.write ("<b> good afternoon </b>");

}
</script>
</body>
</html>

copy of code and not result,why?

Upvotes: 1

Views: 1402

Answers (2)

gaurav
gaurav

Reputation: 62

save ur file as .html instead of .js and open in browser it is inline javascript !!! it should work

Upvotes: 2

Neysor
Neysor

Reputation: 3909

I think you saved your file as txt and not as html. Then the browser would only show you the content and do not render the code.

Save it as HTML File and your problem should be solved.

Upvotes: 4

Related Questions