Help!

Hi all, I have purchased a book. In this book there is a simple code. Please see below. Im using text editor on a mac. With this code Im supposed to get a red background colour, which is not happening. Can you see anything wrong with this code or do you think the text/editor on my mac is not picking up the Javascript code.

<! DOCTYPE html>

<html lang="en">   
         <head>
                  <meta charset=utf-8" />
                  <title>Chapter 1, Example 1</title>
</head>
<body bgcolor="white">
          <p>Paragraph 1<p>
          </script>
                document.bgColor = "red";
           </script>
    </body>
</html>

There should not be a space after !.

Missing quote on attibute. ="utf-8"

Missing endtag on P. </p>

Opening script tag should not have /.


<!DOCTYPE html>
<html lang="en">   
  <head>
    <meta charset="utf-8" />
    <title>Chapter 1, Example 1</title>
  </head>
  <body bgcolor="white">
    <p>Paragraph 1</p>
    <script>
      document.bgColor = "red";
    </script>
  </body>
</html>
3 Likes

It worked, thanks for that, much appreciated.

2 Likes

You may find value in debugging this type of code in the “Codebit” editor, as it will likely catch minor syntax errors (though I understand wanting to try it in a plain-text editor, as I do it myself).

1 Like