+2 william appiah-dankwah · June 10, 2014
i have made an array witch i want to try and use other statements i have learnt to finish of the code, hears my code what can i add to it to make it more interesting 

var gold = new Array();

gold[0] = "goddfellaz";
gold[1] = "sk vibemakers"
gold[2] = "heartless crew"
gold[3] = "rolldeep"
gold[4] = "wolfpack"
gold[5] = "payasyougo"

Post a Reply


- page 1
Oldest  Newest  Rating
+1 Declan Hester · June 11, 2014
When working with arrays most (if not all) of the time, your array will start at 0 and not one. So when we know we have 5 values in front of us, we count it as 1, 2, 3, 4, 5 -- the computer however, counts it as 0, 1, 2, 3, 4. arrayname.length however is a method that returns the count of the variables in the array, starting at 1 and not 0, so it would return a value of 5 because we have 5 values in the array.

Because the loop posted is counting from 0 (i=0) we want to use the same counting scheme as the computer. If the loop's termination condition was i=arrayname.length, we would run in to an Out of Bounds error, because the program we're writing would look for a 6th value which doesn't exist. That's why if our counter variable starts at 0, our termination condition is always < the length of the array.

That's where the poster above you got < arrayname.length from.

As for console.log will work for you if you're using a debugging tool like FireBug for Firefox or the inbuilt debugger for Chrome (if you're using Chrome, all you need to do is right click anywhere on the page, and then click on "Inspect Element". In the window that appears at the bottom of the screen, click on the Console tab. Anything console.log outputs can be found there.)
+1 Ethan Fraser · June 12, 2014
The poster above has posted something that I don't even understand. I believe that's somewhat throwing a toddler in the deep end of a pool and relying entirely on his floaties. I advise you learn the basics of JavaScript, I know that knowing Java helped me but even that didn't prepare me for something like:

var arrayName = ["String 1", "String 2", "String 3"];

for(var x in arrayName) {

That would loop through the array in the same way as I demonstrated in my above post. The difference is simply the way the for loop is made. Each language has it's own quirks, processes and most importantly, functions. Make sure that you learn that language properly, don't just dive into the heavier stuff. It might take longer but it's safer.
0 Sho Carter · April 1, 2015
Hi William 

There are plenty errors in your code:

#1 - "Function" should be lower case.
#2 - "Image" is a reserved name for JavaScript Image object.
#3 - You forgot to put a semi-colon to end the first line. 
#4 - In your loop, you typed "getElement.ById" instead of "getElementById".

I've corrected the issues and placed it below:

0 william appiah-dankwah · April 6, 2015
is the syntax error 

var Name = new Array();

Object[0] = new Image();
Object[1] = "pic/image.jpg"

0 william appiah-dankwah · April 1, 2015
That's not why my loop don't work calling functions like that does not always work do they talk about hacking on this site? By the way just to clear it up its a typo not sure why
0 Sho Carter · April 6, 2015
There's error in that yes, because Object isn't defined., and you haven't placed a semi-colon at the end of Object[1] line
0 Sho Carter · April 1, 2015
Calling functions will only trigger the code inside it. That is how you call a function....
I doubt Bucky would talk about hacking on here...

Btw, I've replaced the code with an image from my text editor, as it won't let me show properly....
0 william appiah-dankwah · April 6, 2015
seriously were ever you are you don't code you who carter your going to have to think about really explaining
0 william appiah-dankwah · April 2, 2015
Yeah it does not work sometimes 
0 Ethan Fraser · June 10, 2014
I'm sorry but again, you need to be more specific. Array can be used in so many ways, what are you using this array for?



A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.