Hi all,
i'm a complete newbie and having real trouble with an assignment using javascript. I'm trying to create some code that allows a user to select some options ie 1 to join the club, where they have to enter their name and age (if they are too young they are told to come back in X years) and i've managed that bit fine. However if they select option 2 they need to be able to view their details ie a 'name' and password which has automatically beed allocated to them using the informaiton they entered at option 1 (in this case the name is the first letter of their first and lat names as well as their age), this is where i'm in a guddle as i've no idea how to do this. Here is the code fo far and i'd be really grateful for any help as it's all getting a bit too confusing for me;
Code:
var forename;
var surname;
var name;
var age, ageDiff;
var password;
var option;
option = 0;
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) - this is where i am confused
{
name = ???
password = ????
document.write('<BR>'+'Your username is,' + name + ' '+'<BR>');
}
}
}
document.write('<BR>'+'Goodbye');