Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #14700 > unrolled thread

JS newbie and Array newbie

Started byrobert@theaustinfamily.us
First post2012-06-26 17:16 -0700
Last post2012-06-29 16:45 -0700
Articles 6 — 5 participants

Back to article view | Back to comp.lang.javascript


Contents

  JS newbie and Array newbie robert@theaustinfamily.us - 2012-06-26 17:16 -0700
    Re: JS newbie and Array newbie Stefan Weiss <krewecherl@gmail.com> - 2012-06-27 02:37 +0200
      Re: JS newbie and Array newbie RoLaAus <robert@theaustinfamily.us> - 2012-06-27 16:56 -0700
    Re: JS newbie and Array newbie Gregor Kofler <usenet@gregorkofler.com> - 2012-06-27 11:00 +0200
      Re: JS newbie and Array newbie RoLaAus <robert@theaustinfamily.us> - 2012-06-27 17:01 -0700
        Re: JS newbie and Array newbie "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2012-06-29 16:45 -0700

#14700 — JS newbie and Array newbie

Fromrobert@theaustinfamily.us
Date2012-06-26 17:16 -0700
SubjectJS newbie and Array newbie
Message-ID<d1e9e795-70bd-498d-8e0d-48511a59cf37@googlegroups.com>
Okay, I've been around coding for about 15 years (consider myself more of a data analyst that uses programming as a tool, rather than a full fledged programmer). So, I know my way around OOP. However, I have never needed to use an Array, but I get the basic concept down - and I *do* know how to search to find out what I need, unfortunately, this one is stumping me. I'm trying to enter the code I have found as closely as possible, and just changing the names to be specific to what I want, instead of using the typical "c", or "x", etc.

Here is what I have - and isn't working for whatever reason;

  function myPlanet(inPosX, inPosY, inName) {
        this.posX = inPosX;
        this.posY = inPosY;
        this.myName = inName;
    }
this is *supposed* to create a new "planet" object (called myPlanet)

and I call this function with the following code
var objPlanets = new myPlanet(myX, myY, ****);

** my "planet name" - for the time being, I was wanting to use the combination of myX and myY and no matter what I try to place into the name variable, I can't get it to work!

Any and all suggestions would be greatly appreciated. Thanks

[toc] | [next] | [standalone]


#14702

FromStefan Weiss <krewecherl@gmail.com>
Date2012-06-27 02:37 +0200
Message-ID<jsdl56$5rr$1@news.albasani.net>
In reply to#14700
On 2012-06-27 02:16, robert@theaustinfamily.us wrote:
> Here is what I have - and isn't working for whatever reason;
> 
>   function myPlanet(inPosX, inPosY, inName) {
>         this.posX = inPosX;
>         this.posY = inPosY;
>         this.myName = inName;
>     }
> this is *supposed* to create a new "planet" object (called myPlanet)
> 
> and I call this function with the following code
> var objPlanets = new myPlanet(myX, myY, ****);
> 
> ** my "planet name" - for the time being, I was wanting to use the
> combination of myX and myY and no matter what I try to place into the
> name variable, I can't get it to work!

I don't understand your problem. What you posted should work fine:

  function myPlanet(inPosX, inPosY, inName) {
    this.posX = inPosX;
    this.posY = inPosY;
    this.myName = inName;
  }

  var objPlanets = new myPlanet(23, 34, "the name");

  alert(objPlanets.posX);
  alert(objPlanets.posY);
  alert(objPlanets.myName);

Does this not show three alerts for the three arguments you passed to
the myPlanet constructor?

And what does this have to do with arrays?

- stefan

[toc] | [prev] | [next] | [standalone]


#14733

FromRoLaAus <robert@theaustinfamily.us>
Date2012-06-27 16:56 -0700
Message-ID<29b263a4-d7d2-4ff3-bd97-bab348218e45@googlegroups.com>
In reply to#14702
On Tuesday, June 26, 2012 5:37:03 PM UTC-7, Stefan Weiss wrote:
> On 2012-06-27 02:16, robert@theaustinfamily.us wrote:
> > Here is what I have - and isn't working for whatever reason;
> > 
> >   function myPlanet(inPosX, inPosY, inName) {
> >         this.posX = inPosX;
> >         this.posY = inPosY;
> >         this.myName = inName;
> >     }
> > this is *supposed* to create a new "planet" object (called myPlanet)
> > 
> > and I call this function with the following code
> > var objPlanets = new myPlanet(myX, myY, ****);
> > 
> > ** my "planet name" - for the time being, I was wanting to use the
> > combination of myX and myY and no matter what I try to place into the
> > name variable, I can't get it to work!
> 
> I don't understand your problem. What you posted should work fine:
> 
>   function myPlanet(inPosX, inPosY, inName) {
>     this.posX = inPosX;
>     this.posY = inPosY;
>     this.myName = inName;
>   }
> 
>   var objPlanets = new myPlanet(23, 34, "the name");
> 
>   alert(objPlanets.posX);
>   alert(objPlanets.posY);
>   alert(objPlanets.myName);
> 
> Does this not show three alerts for the three arguments you passed to
> the myPlanet constructor?
> 
> And what does this have to do with arrays?
> 
> - stefan

Okay, well, I knew it must have been something stupid, and true enough, it was (sort 0f).

I was trying to debug this project by using the Alert() function, but mine went like this
alert(objPalnet(myName));

Now, as for the array part, I am trying (as should be obvious) trying to build a list of several planets, and will need a way to find specific details about each individual one, normally I would use database tools, creating record sets and be able to do whatever I want with the RecordSet object, but as I said, I'm branching out here and trying to learn something new.

This is a completely separate issue, and would be more than happy to post in a new thread if necessary, but I do already have two people keeping up with this thread with responses, so I figure I might as well follow up this roadblock with another, separate but related issue.

Given that I have a list of multiple planets, how would I go about retrieving say, the population of the planet named 'Earth'?

[toc] | [prev] | [next] | [standalone]


#14704

FromGregor Kofler <usenet@gregorkofler.com>
Date2012-06-27 11:00 +0200
Message-ID<jsei3e$p8k$1@dont-email.me>
In reply to#14700
Am 2012-06-27 02:16, schrieb robert@theaustinfamily.us:
> Okay, I've been around coding for about 15 years (consider myself more of a data analyst that uses programming as a tool, rather than a full fledged programmer). So, I know my way around OOP. However, I have never needed to use an Array, but I get the basic concept down - and I *do* know how to search to find out what I need, unfortunately, this one is stumping me. I'm trying to enter the code I have found as closely as possible, and just changing the names to be specific to what I want, instead of using the typical "c", or "x", etc.
>
> Here is what I have - and isn't working for whatever reason;
>
>    function myPlanet(inPosX, inPosY, inName) {
>          this.posX = inPosX;
>          this.posY = inPosY;
>          this.myName = inName;
>      }
> this is *supposed* to create a new "planet" object (called myPlanet)
>
> and I call this function with the following code
> var objPlanets = new myPlanet(myX, myY, ****);
>
> ** my "planet name" - for the time being, I was wanting to use the combination of myX and myY and no matter what I try to place into the name variable, I can't get it to work!

*What* is not working? There are no obvious bugs in your script. On a 
side note: constructors should start with an uppercase letter.


Gregor

[toc] | [prev] | [next] | [standalone]


#14734

FromRoLaAus <robert@theaustinfamily.us>
Date2012-06-27 17:01 -0700
Message-ID<a109efd5-a4cc-47e7-8511-a00721d4efa9@googlegroups.com>
In reply to#14704
On Wednesday, June 27, 2012 2:00:30 AM UTC-7, Gregor Kofler wrote:
> Am 2012-06-27 02:16, schrieb robert@theaustinfamily.us:
> > Okay, I've been around coding for about 15 years (consider myself more of a data analyst that uses programming as a tool, rather than a full fledged programmer). So, I know my way around OOP. However, I have never needed to use an Array, but I get the basic concept down - and I *do* know how to search to find out what I need, unfortunately, this one is stumping me. I'm trying to enter the code I have found as closely as possible, and just changing the names to be specific to what I want, instead of using the typical "c", or "x", etc.
> >
> > Here is what I have - and isn't working for whatever reason;
> >
> >    function myPlanet(inPosX, inPosY, inName) {
> >          this.posX = inPosX;
> >          this.posY = inPosY;
> >          this.myName = inName;
> >      }
> > this is *supposed* to create a new "planet" object (called myPlanet)
> >
> > and I call this function with the following code
> > var objPlanets = new myPlanet(myX, myY, ****);
> >
> > ** my "planet name" - for the time being, I was wanting to use the combination of myX and myY and no matter what I try to place into the name variable, I can't get it to work!
> 
> *What* is not working? There are no obvious bugs in your script. On a 
> side note: constructors should start with an uppercase letter.
> 
> 
> Gregor

I posted a response to the other comment about what isn't working, but I will re-interate that I was trying to get a planet name using alert(objPlanets(myName));

The posted solution does return what I was wanting, if I wrote the proper syntax (objPanets.myName) ... what I was initially trying with the above was to get what I thought was going to be the Index of the newly created Planet object. (now that the proper syntax was pointed out to me, I feel a "dugh" moment coming on).

As I may have mentioned, I'm trying to branch out and learn something new, so I'm writing this "HTML5 Canvas" app using Visual Studio (mainly for formatting help and the add-in that helps with indents and closing brackets, etc. - I suppose I could try finding similar features and using NotePad++ but the point I'm trying to make is that there really isn't a debug functionality or even a "compile" for that matter.  Is there a recommended tool to use that I am overlooking? Maybe something with intellisense for JavaScript?

[toc] | [prev] | [next] | [standalone]


#14775

From"Michael Haufe (TNO)" <tno@thenewobjective.com>
Date2012-06-29 16:45 -0700
Message-ID<0ac92ff3-9279-4e50-86d2-d0f6110c5b40@googlegroups.com>
In reply to#14734
On Wednesday, June 27, 2012 7:01:22 PM UTC-5, RoLaAus wrote:

> As I may have mentioned, I'm trying to branch out and learn something new, so I'm writing this "HTML5 Canvas" app using Visual Studio (mainly for formatting help and the add-in that helps with indents and closing brackets, etc. - I suppose I could try finding similar features and using NotePad++ but the point I'm trying to make is that there really isn't a debug functionality or even a "compile" for that matter.  Is there a recommended tool to use that I am overlooking? Maybe something with intellisense for JavaScript?

To answer the basic questions about the language you didn't know to ask:

<https://developer.mozilla.org/en/JavaScript>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web