Welcome to Dream.In.Code
Getting Help is Easy!

Join 119,727 Programmers for FREE! Ask your question and get quick answers from experts. There are 1,361 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



If Statements not working

 
Reply to this topicStart new topic

If Statements not working

confussed
post 23 Jun, 2008 - 07:00 AM
Post #1


New D.I.C Head

*
Joined: 23 Jun, 2008
Posts: 3

I've kind of given up on this but Just in case someone can help me. I need to have a password and a username allocated for a user if they select option 2, where the username is the first initial from their forename, the first initial from their last name - and their age, and the password is their age - the last letter of their surname and the last letter of thier first name but i cannot get it to work and i'm giving up as it is only the first question. Here is the code


jscript

var forename;
var surname;
var userName;
var age, ageDiff;
var password;
var option;
option = 0;

document.write('REGISTER'+'<BR>'+
'============================='+'<BR>'+
'What would you like to do?'+'<BR>'+
'<OL>'+
'<LI>'+'Register as a new reader'+'</LI>'+
'<LI>'+'View your details'+'</LI>'+
'<LI>'+'Exit'+'</LI>'+
'</OL>'+
'Enter 1, 2 or 3 to select'+'<BR>')

while (option != 3)
{
option = window.prompt('Please select an option between 1 and 3.','');
option = parseFloat(option);
while (option < 1 || option > 3)
{
option = window.prompt('You must select an option between 1 and 3.','');
option = parseFloat(option);
}

if (option == 1)
{
forename = window.prompt('Please enter your forename ','');
surname = window.prompt('Please enter your surname ', '');
age = window.prompt('Please enter your age ', '');
age = parseFloat(age);
}
if (age < 5 || age > 120)
{
age = window.prompt('Please re enter your age ', '');
age = parseFloat(age);
}
if (age < 5)
{
ageDiff = (5 - age)
document.write('<BR>'+'Sorry, you are too young. Come back in ' + ageDiff + ' year.');
}
else if (option == 1){
{
document.write('<BR>'+'Thank you, ' + forename + ' ' + surname + '.' + ' You are now a member '+'<BR>');
}
if (option == 2)
{
userName = forename.substr(0,1).toUpperCase() + surname.substr(0,1).toUpperCase() + -"+age
password = age+"-"+surname.substr(surname.length-1,1)+forename.substr(forename.length-1,1)
document.write('<BR>'+'<BR>'+'Username: '+ userName + '<BR><BR>Password: '+ password)
}
}
}
document.write('<BR>'+'GOODBYE ');


Mod Edit: Please use code tags when posting your code. They're used like so: => code.gif

Thanks,
PsychoCoder smile.gif
User is offlineProfile CardPM

Go to the top of the page


cavvysri
post 23 Jun, 2008 - 09:41 AM
Post #2


New D.I.C Head

*
Joined: 12 Jun, 2008
Posts: 29


My Contributions


in the line you have which is userName =.....

try using the charAt that was in unit 7(i think) i.e. forename.charAt(0)

this will read the first letter of the forename, same goes for surname. for the last letter, you will need to use forename.length - 1

hope that makes sense, dont want to give too much away as i could get in trouble lol..

email me if your stuck

Cav
User is offlineProfile CardPM

Go to the top of the page

confussed
post 23 Jun, 2008 - 01:23 PM
Post #3


New D.I.C Head

*
Joined: 23 Jun, 2008
Posts: 3

Thanks Cav, but the code still does not work for me, i think it's just a bit beyond me. i just can't seem to get anything to work and i'm stressing so much about it all. I have not been able to get beyond this part at all.
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 10/15/08 04:15PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month