0

This is a code that I'm using to practice. The prompt line works. However, nothing gets printed into the browser when I run it on both chrome and firefox. I've also tried using <br> instead of <br/> with no luck.

<!DOCTYPE html>

<html lang="en">
<head>
    <title>Chapter 2, Example 5</title>
</head>
<body>
    <script>
        var greetingString = "Hello";
        var MyName = prompt("Please enter your name");
        var concatString;

        document.write(greetingString + " " + myName + "<br/>");

        concatString = greetingString + " " + myName;

        document.write(concatString);
    </script>
</body>
</html>

As others have mentioned about the book, it is using some dated terminology such as .bgColor. However, I checked and neither document.write() or <br> is depreciated.

James
  • 127
  • 10
  • 4
    `myName` and `MyName` are two different symbols. – Pointy Jun 22 '16 at 20:36
  • 1
    You may want to consider a more modern learning source such as code academy. I don't think anyone uses document.write anymore. Also, check your js console for errors. It looks like `myName` is undefined. – dlsso Jun 22 '16 at 20:39
  • Thanks. Is the use of `
    ` or `
    ` recommended? Also, do most modern webpages include the `lang="en"` in the html section?
    – James Jun 22 '16 at 20:40
  • 1
    Please take a look in the browser console (by pressing F12). All the errors are reported there. – Sebastian Simon Jun 22 '16 at 20:41
  • As for the `
    ` question: [HTML 5: Is it
    ,
    , or
    ?](http://stackoverflow.com/q/1946426/4642212). As for the `lang="en"` question: it’s better for semantics and SEO to have it. See [What is lang attribute of the tag used for?](http://stackoverflow.com/q/14649798/4642212). All your questions are already answered elsewhere.
    – Sebastian Simon Jun 22 '16 at 20:43
  • @dlsso I have already finished the JS coarse at codecademy and was looking in finishing an actual book (Beginning JavaScript 5th ed.). – James Jun 22 '16 at 20:43
  • If that book teaches you to use `document.write`, then it’s better used for Christmas — inside the fireplace. Please refer to more up-to-date tutorial sites like [MDN](https://developer.mozilla.org/en/docs/Web) instead. – Sebastian Simon Jun 22 '16 at 20:46
  • @James if you've already done the web basics and JS tracks you can probably learn the most just by picking a project and building it, googling when you run into something you don't know. – dlsso Jun 22 '16 at 20:49

1 Answers1

0

Change "var MyName"

to "var myName".

These 2 things are different since Javascript is case sensitive

cssGEEK
  • 994
  • 2
  • 15
  • 38