I currently have a problem with some Javascript code that I can't seem to figure out.
Full disclosure: I've never really played with Javascript before. I've used (X)HTML, CSS and PHP, but that's about it. I was never really a fan of it, but I was recently tasked with creating a site for someone and we included Google Maps in it.
Thus, there wasn't really any better way of learning than to dive right in, head-first.

Anyway, after perusing the Google Maps API documentation and combining the JS syntax and logic with what I remember from PHP, I have the map itself working properly.

The problem I am having right now is that I am trying to create a function to automatically populate an InfoWindow.
Specifically, the problem seems to be that if I pass numbers to the function, it works fine, but when I attempt to pass letters to the function, it breaks and my tools are telling me that the argument is undefined. I'm trying to look around for an answer, but I am far too new at this to figure out Javascript's intricacies just yet. :(

It looks as though your parameters are used to form filenames. Either way they must be quoted or they will be treated as variable names:

Code:

mtaSmall("A", "B", "C")

09-13-2013, 11:55 PM

DarkScythe

Quote:

Originally Posted by Logic Ali

It looks as though your parameters are used to form filenames. Either way they must be quoted or they will be treated as variable names:

Code:

mtaSmall("A", "B", "C")

Wow, that was exactly it. Thank you!
For some reason I didn't think of encapsulating them inside quotes like that, since none of the other functions seemed to need them. I also thought the quotes might have gone together with the letters, and the function would wind up trying to search for an "A".gif, or something.

I am curious, though, why did it work with numbers, but not letters? And even then, it was single letters; I have other functions that are written in very similar formats and they accept unquoted short strings/words without a problem. Is there something special with using singular letters?

09-14-2013, 02:25 AM

tenfold

Quote:

Originally Posted by DarkScythe

I am curious, though, why did it work with numbers, but not letters? And even then, it was single letters; I have other functions that are written in very similar formats and they accept unquoted short strings/words without a problem. Is there something special with using singular letters?

Nah. When you don't use quotes (aka. pass a string), you attempt to pass a reference of the variable instead, not a string.
The number works because it's simply that, a number. It's not a variable; It's a primitive value. I'm not good at explaining, so maybe someone else can clarify.

09-14-2013, 12:38 PM

DarkScythe

Thanks!

My friend also explained it to me, so I understand the reasoning now. It was pretty simple, as he asked what I would have expected to happen if instead of passing mtaSmall(A, B, C) that I had passed mtaSmall(A, B, iconArray) instead. There I was able to say immediately that iconArray did not yet exist as a global array, which led me to realize that I was automatically treating that third parameter as a variable instead of a literal string I was trying to pass A and B as.
Looking back at my other functions, it's become pretty clear what was happening - even though all the other functions were passed arguments without quotes, they had already been defined as variables that I declared globally.
I am now much clearer on the usage of quotes to pass either variables or literal strings into my functions.

The only lingering question I have is whether there is a difference between single quotes and double quotes.

09-18-2013, 02:28 AM

tenfold

Quote:

Originally Posted by DarkScythe

The only lingering question I have is whether there is a difference between single quotes and double quotes.