Search code examples
javascripthtmldocument.write

Javascript and print on the page


I started to learn javascript and I saw the following code in one of Javascript books:

<!DOCTYPE html>
<html>
    <head>
        <title>A Simple JavaScript Example</title>
    </head>
<body>
    <p>Printed before JavaScript is run.</p>
    <p>
        <script type=”text/javascript”>
        document.write(“Printed by JavaScript.”);
        </script>
    </p>
    <p>Printed after JavaScript is run.</p>
</body>
</html>

According to the book, three lines has to be printed. However, when I open this html file in the browser I see only the first and the last lines. The line "Printed by JavaScript" doesn't show.

Do you have any idea what can be the problem?


Solution

  • I guess it's because you used incorrect double quotes (wrong copy-paste from the book sample):

    should become:

    "
    

    so that you have:

    <script type="text/javascript">
        document.write("Printed by JavaScript.");
    </script>