"Functions in Javascript" Help

Hey guys, this might be a really obvious noob question but I’d really appreciate some clarification here

I am following along the “functions in Javascript” video and typing the same code in Atom that Ivan is typing out in the video. But for some reason, no greeting message appears. The only text I see on the webpage is the “this is the title” text.

Here’s what I wrote:

<html>

  <head>

      <title>Great website </title>

      </head>

      <body>

          <h1> this is the title </h1>

          <script>

            function greet (name){
              document.write ("<h1>Greetings " + name "</h1>");
            }

            greet("Jim");

          </script>

          </body>
</html>

I thought I typed everything exactly t he same but my code doesn’t do the same things as Ivan. Can someone explain what I’m missing? Thanks!

1 Like

Hiya mate. You need to and another + sign after name. so document.write ("<h1>Greetings " + name + "</h1>");

2 Likes

Wow, thank you so much dude! That was starting to drive me a little crazy lol.

2 Likes

LOL. Yes it can drive you a little mad sometimes. :crazy_face: Happy to help :+1:

2 Likes

When you need to concatenate a string with a variable "string " + variable name + “rest of sting”
but I’m sure you get it now.

2 Likes

Thank you for helping out Nick. I appreciate it. :raised_hands:

3 Likes

Hi Bunbo, you have missed the “+” after the name. this should work

document.write ("<h1>Greetings " + name + "</h1>");
3 Likes

Thank you so much @abuga !

2 Likes