Results 1 to 4 of 4
  1. #1
    Davda is offline Member
    Join Date
    May 2012
    Posts
    1
    Rep Power
    0

    Default Help with simple program

    I have two questions. First how do I paste code? And second I want a program that asks your name then your gender. If you are a girl I want it to ask if you are married (For ms. or mrs. purposes). However I do not want the program to ask that if you are a boy. Here is what I have. What have I done wrong?

    var name = prompt("Name");
    var gender=prompt("Gender");
    if(gender==="female"||"girl"){
    var result=prompt("are you married");
    if (result==="yes"){
    console.log("Hello Mrs."+name);

    }else{
    console.log("Hello Ms."+name);
    }
    }else{
    console.log("Hello Mr."+name);
    }

  2. #2
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default Re: Help with simple program

    That's Javascript, and not Java. Java and Javascript are different languages. I suggest you look for a javascript forum.

    That said, I double
    Java Code:
    if(gender==="female"||"girl"){
    ...
    }
    and I suspect you will want something like

    Java Code:
    if(gender==="female" || gender==="girl"){
    ...
    }

  3. #3
    Bushman is offline Member
    Join Date
    Apr 2012
    Location
    Spainish TOwn
    Posts
    25
    Rep Power
    0

    Default Re: Help with simple program

    Although you shouldn't post this here, I will aid you anyway.

    first, you append code to this forum appropriately via adding code tags.


    By bushman21 at 2012-05-07


    By bushman21 at 2012-05-07

    When your code is now properly tagged, it will appear like so:
    PHP Code:
    var name = prompt("Name");
    var gender=prompt("Gender");
         if(gender=="female"||"girl")
         {
              var result=prompt("are you married");
              if (result=="yes")
              {
                   console.log("Hello Mrs."+name);
              }
              else
              {
                   console.log("Hello Ms."+name);
              }
         }
         else
         {
              console.log("Hello Mr."+name);
         }
    Also u need to indent you sh*t.



    Lol now for the actual solution. This might be the solution. you have === three equal signs for your comparison scheme. This is wrong. You need only two equal symbols to compare strings in javascript.

    Also, as said by previous user, you need: (gender=="female"|| gender=="girl")

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,457
    Rep Power
    20

    Default Re: Help with simple program

    Off topic. Closing the thread and moving to the Lobby.

    db

    THREAD CLOSED
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Help with a simple tax program
    By Shea6892 in forum New To Java
    Replies: 3
    Last Post: 02-03-2012, 06:35 PM
  2. Simple program, simple problem
    By taymilll in forum New To Java
    Replies: 12
    Last Post: 06-20-2011, 06:12 AM
  3. Please help with simple program.. Very simple.
    By jonytek in forum New To Java
    Replies: 7
    Last Post: 02-14-2011, 01:44 AM
  4. simple program
    By blastoff in forum New To Java
    Replies: 5
    Last Post: 04-15-2010, 12:25 AM
  5. Simple Program
    By TheRocket in forum Advanced Java
    Replies: 15
    Last Post: 12-30-2008, 03:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •