Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Functions

AadanAadan DallasMember Posts: 1
edited December 2015 in HTML & WEB-Design

What am I doing wrong ? I'm trying to create a function that adds two names together

Example:
You get to my site and an alert comes up and asks you "What is your name"
You enter the name and it then tells you "hello _______"
You are then asked again "what is your name?"
Again it tells you "Hello_____"
Now I need to create a function that passes through two parameters and it's supposed to say "Greetings "name 1" + "name 2"

Here is my html document: Where am I going wrong ?


var name=prompt("What is your name?"); alert("Hello! "+name) var name=prompt("What is your name?"); alert("Hello! "+name)


Comments

  • MonetishMonetish TexasMember Posts: 5

    Hi Aadan,
    I believe I'm in your class as well. Looking at your code a couple things... And some might just be you writing quick hand in this site, so I apologize if so, but here is what I see ( without giving you the WHOLE answer)

    1. name 1 and name 2, make sure they are not in quotes since they are variables and also be sure there is not a space ... name1 name2

    2. When you're creating your function, that is where you should put your alert where you add both the names

    3. Your function should be something like function greet(name1, name2), then use the variables for the names to write your alert in the function ( my point above in #2)

    4. Make sure you have your function set up at the beginning, either in the head or the start of the body

    5. Then do you prompts in the body storing them in 2 different var, though there is probably a way you could write it keeping the same var name... The way I'm writing it/explaining it you would create 2 so the first name entered is stored in that "mailbox" and then the second name entered is stored in a different "mailbox"/ var. it looks like above you are using name for both prompts, the second prompt entry will replace the first and you need them both for your function

    6. Then finally you call your function ( in my example greet(. , ) ) and put your prompt var's in the parenthesis

    I hope that makes sense. Write me on the class board if you need more help
    ...

Sign In or Register to comment.