adamdressler
09-29-2011, 05:45 AM
Hello all.
I have a script to prompt a user for 4 pieces of information.
First name.
Last name
Area code.
& Telephone number.
My assignment was to do this, and put the information is as follows.
If both, first name & last name are entered, store in object as
last name,first name.
If only one is entered. display without the comma.
Also store telephone number in (XXX) XXX-XXXX format.
I was told to use methods to do all of these things.
Please take note I am in a VERY basic javascript class.
Thanks in advance.
CODE I HAVE SO FAR :
head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
last=name=area=num='';
function info ( ) {
last = prompt("Please enter your last name",'');
name = prompt("Please enter your first name",'');
area = prompt("Please enter your area code",'');
num = prompt("Please enter your phone number",'');
};
function Person (info) {
this.name = name
this.last = last
this.area = area
this.num = num
}
</script>
<title></title>
</head>
<body>
<script type="text/javascript">
info ( );
teacher = new Person();
tempString='';
document.writeln ( last );
document.writeln ( name) ;
if(area==''||num==''){tempString='';}
else{tempString = teacher.area +''+ teacher.num}
document.writeln ( tempString);
</script>
I have a script to prompt a user for 4 pieces of information.
First name.
Last name
Area code.
& Telephone number.
My assignment was to do this, and put the information is as follows.
If both, first name & last name are entered, store in object as
last name,first name.
If only one is entered. display without the comma.
Also store telephone number in (XXX) XXX-XXXX format.
I was told to use methods to do all of these things.
Please take note I am in a VERY basic javascript class.
Thanks in advance.
CODE I HAVE SO FAR :
head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
last=name=area=num='';
function info ( ) {
last = prompt("Please enter your last name",'');
name = prompt("Please enter your first name",'');
area = prompt("Please enter your area code",'');
num = prompt("Please enter your phone number",'');
};
function Person (info) {
this.name = name
this.last = last
this.area = area
this.num = num
}
</script>
<title></title>
</head>
<body>
<script type="text/javascript">
info ( );
teacher = new Person();
tempString='';
document.writeln ( last );
document.writeln ( name) ;
if(area==''||num==''){tempString='';}
else{tempString = teacher.area +''+ teacher.num}
document.writeln ( tempString);
</script>