Results 1 to 4 of 4
Thread: Help with simple program
- 05-08-2012, 05:58 AM #1
Member
- Join Date
- May 2012
- Posts
- 1
- Rep Power
- 0
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);
}
- 05-08-2012, 06:01 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
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
and I suspect you will want something likeJava Code:if(gender==="female"||"girl"){ ... }
Java Code:if(gender==="female" || gender==="girl"){ ... }
- 05-08-2012, 06:15 AM #3
Member
- Join Date
- Apr 2012
- Location
- Spainish TOwn
- Posts
- 25
- Rep Power
- 0
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:
Also u need to indent you sh*t.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); }
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")
- 05-08-2012, 12:27 PM #4
Similar Threads
-
Help with a simple tax program
By Shea6892 in forum New To JavaReplies: 3Last Post: 02-03-2012, 05:35 PM -
Simple program, simple problem
By taymilll in forum New To JavaReplies: 12Last Post: 06-20-2011, 05:12 AM -
Please help with simple program.. Very simple.
By jonytek in forum New To JavaReplies: 7Last Post: 02-14-2011, 12:44 AM -
simple program
By blastoff in forum New To JavaReplies: 5Last Post: 04-14-2010, 11:25 PM -
Simple Program
By TheRocket in forum Advanced JavaReplies: 15Last Post: 12-30-2008, 02:35 PM


LinkBack URL
About LinkBacks

Bookmarks