List Info

Thread: RE: L of a Learner !




RE: L of a Learner !
country flaguser name
Japan
2008-03-10 19:22:14

I don't know what you're using as a debugging tool, but there are minor
problems you need to resolve ...

> var stToday = new Date.getDate();

Not sure what you're trying for here, it's a bit confused. "st"
suggests you are going for a string, but you try to give it a "new" and
you try to use it as a date in the next line. However, getDate() will
indeed give you a string. I assume you simply want a date object with
today's date in it. Then:

var today = new Date();
var stYear = today.getFullYear();

Next syntax problem, "srEnroll is undefined". Indeed it is, it should
be stEnroll.

srEnroll[2] = john_nosbod; becomes stEnroll[2] = john_nosbod;

Next syntax problem, "stName is undefined", and also stSurname, etc.
(This is inside your FOR loop.) These items don't exist by themselves,
they are members of the student object. So you need to qualify them
with the student object. (And they themselves are not defined as arrays
inside student, so they don't take subscripts.)

Also, student.length is not important here. That's the length of ONE
student object. You've put the student objects into an array called
stEnroll. That's the thing you want the length of.

And, last but not least, your FOR is from 0 while <= length. That's one
too many. You need to go from 0 while < length.

So

for (i=0;i<=student.length;i+;+) {
lineString = ("<;br />&nbsp;" + stName[i] + " " + stSurname[i]);
lineString += (" " + stOUCU[i] + " &nbsp; YoB = " + stYoBirth[i] + "
&quot;);
lineString += (" Age = " + stAge[i] + " &nbsp; ");
document.write(lineString);
};

becomes

for (i=0;i<stEnroll.length;i+;+) {
lineString = ("<;br />&nbsp;" + stEnroll[i].stName + " " +
stEnroll[i].stSurname);
lineString += (" " + stEnroll[i].stOUCU + " &nbsp; YoB = " +
stEnroll[i].stYoBirth + " ");
lineString += (" Age = " + stEnroll[i].stAge + " &nbsp; ");
document.write(lineString);
};

I suppose your misunderstanding stems from "Array Objects&quot;. What you
have here are objects (student) which you happen to be putting into an
array (stEnroll). But the objects are not "array" themselves.

In fact, you could have left the individual students in their individual
variables and used them from there. E.g.

document.write("<br />&nbsp;" + bob_sharp.stName + " " +
bob_sharp.stSurname +
" " + bob_sharp.stOUCU + " &nbsp; YoB = " +
bob_sharp.stYoBirth + " " +
" Age = " + bob_sharp.stAge + " &nbsp; ");

(outside your FOR loop) gives you Bob's information.

Dave

PS my complete version of yours (plus my extra copy of Bob's info) ...

&lt;!doctype html public "-//w3c//dtd html 3.2//en&quot;>

<html&gt;

&lt;head>
<title>(Type a title for your page here)</title>
<meta name=";GENERATOR&quot; content=&quot;Arachnophilia 4.0"&gt;
<meta name=";FORMATTER&quot; content=&quot;Arachnophilia 4.0"&gt;

&lt;script language=&quot;JavaScript" type=";text/javascript";>
/* <![CDATA[ */

var today = new Date();
var stYear = today.getFullYear();

function student (stName,stSurname,stOUCU,stPI,stRegion,stYoBirth) {
this.stName = stName;
this.stSurname = stSurname;
this.stOUCU = stOUCU;
this.stPI = stPI;
this.stRegion = stRegion;
this.stYoBirth = stYoBirth;
this.stage = age;
this.stAge = age();
};

var john_wilson = new student ("John", "Wilson", "jw9372", "AB12345678";,
1, 1986);
var bob_sharp = new student ("Bob", "Sharp",&quot;bs3578&quot;, "y9031527", 1,
1951);
var john_nosbod = new student ("John", "Nosbod", "nb1234", "z1234567",
1, 1952);
var peter_cams = new student ("Peter", "Camilleri", "pc9876",
"a9876543", 1, 1989);

var stEnroll = new Array;
stEnroll[0] = john_wilson;
stEnroll[1] = bob_sharp;
stEnroll[2] = john_nosbod;
stEnroll[3] = peter_cams;

function age() {
return (stYear - this.stYoBirth);
};

/* ]]> */
</script>

</head>

<body bgcolor=&quot;#ffffff" text=";#000000&quot; link=";#0000ff&quot; vlink=&quot;#800080&quot;
alink="#ff0000">

&lt;div class=&quot;sDivMain&quot;>
<script language=&quot;JavaScript" type=";text/javascript";>
/*&lt;![CDATA[*/

var i = 0;
// alert(stEnroll.length);

document.write("&lt;br />&nbsp;" + bob_sharp.stName + " " +
bob_sharp.stSurname +
" " + bob_sharp.stOUCU + " &nbsp; YoB = " +
bob_sharp.stYoBirth + " " +
" Age = " + bob_sharp.stAge + " &nbsp; ");

for (i=0;i<stEnroll.length;i+;+) {
lineString = ("<;br />&nbsp;" + stEnroll[i].stName + " " +
stEnroll[i].stSurname);
lineString += (" " + stEnroll[i].stOUCU + " &nbsp; YoB = " +
stEnroll[i].stYoBirth + " ");
lineString += (" Age = " + stEnroll[i].stAge + " &nbsp; ");
document.write(lineString);
};
/*]]>;*/
</script>
</div&gt;

&lt;/body>

</html>

----- Original Message -----
From: "Bob Sharp"; < bobsharp%40ntlworld.com">bobsharpntlworld.com>
To: < JavaScript_Official%40yahoogroups.com">JavaScript_Officialyahoogroups.com>
Sent: Tuesday, March 11, 2008 12:21 AM
Subject: [JavaScript] L of a Learner !

>; Hope there is someone who can see where I am coming from, where I'm
> headed, and stop me before I get there.
> Maybe I'm not understanding the concept of Array Objects.
>
> cheers
&gt;
>
>
> in <HEAD&gt; ...
> <script language=&quot;JavaScript" type=";text/javascript";>
>; /* <![CDATA[ */
>
> var stToday = new Date.getDate();
&gt; var stYear = stToday.getFullYear();
>
> function student
> (stName,stSurname,stOUCU,stPI,stRegion,stYoBirth) {
> this.stName = stName;
> this.stSurname = stSurname;
> this.stOUCU = stOUCU;
> this.stPI = stPI;
&gt; this.stRegion = stRegion;
> this.stYoBirth = stYoBirth;
> this.stage = age;
>; this.stAge = age();
&gt; };
>
> var john_wilson = new student
> ("John", "Wilson", "jw9372", "AB12345678";, 1, 1986);
&gt; var bob_sharp = new student
> ("Bob", "Sharp",&quot;bs3578&quot;, "y9031527", 1, 1951);
&gt; var john_nosbod = new student
> ("John", "Nosbod", "nb1234", "z1234567", 1, 1952);
&gt; var peter_cams = new student
> ("Peter", "Camilleri", "pc9876", "a9876543", 1, 1989);
&gt;
> var stEnroll = new Array;
&gt; stEnroll[0] = john_wilson;
> stEnroll[1] = bob_sharp;
> srEnroll[2] = john_nosbod;
> stEnroll[3] = peter_cams;
>
> function age() {
> return (stYear - this.stYoBirth);
&gt; };
>
> /* ]]> */
> </script>
>;
>
> in <BODY&gt; ...
> <div class=&quot;sDivMain&quot;>
> <script
> language=&quot;JavaScript" type=";text/javascript";>
>; /*<![CDATA[*/
&gt;
> var i = 0;
> /*
> alert(student.length); */
>
> for (i=0;i<=student.length;i+;+) {
>
> lineString = ("<;br />&nbsp;" + stName[i] + " " +
> stSurname[i]);
>;
> lineString += (" " + stOUCU[i] + " &nbsp; YoB = " +
> stYoBirth[i] + " ");
>
> lineString += (" Age = " + stAge[i] + " &nbsp; ");
>
>
>
> document.write(lineString);
>
> };
> /*]]>*/
> </script>
>; </div&gt;
>
>
>
>
>
> Visit http://aiaiai.com for more groups to join
> Yahoo! Groups Links
&gt;
>
>
Visit our website at http://www.ubs.com

This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.

E-mails are not encrypted and cannot be guaranteed to be secure or
error-free as information could be intercepted, corrupted, lost,
destroyed, arrive late or incomplete, or contain viruses. The sender
therefore does not accept liability for any errors or omissions in the
contents of this message which arise as a result of e-mail transmission.
If verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities
or related financial instruments.

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )