arrays

+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

Replies

- page 4
Oldest  Newest  Rating
0 Hope Lasr · June 12, 2014
@william appiah-dankwah 

I think you really need to learn some JavaScript basics, it really would help you a lot, I see you are saying that condole.log() does not work, did you try CTRL(control Key) + F12 or FN + F12 depending on your keyboard, then navigate to the  "Console" Tab of your browser's Developer tools? I think that would help.

Please understand that Console.log() is more like your document.write() but the difference is that document.write() will write the output to the page(document) that you are viewing whereas Console.log() will write on the Browsers console. 

Hope that Helps.
0 michael walker · March 30, 2015
event simpler way to display items from an array would be
CODE:
var ArrayName = new Array("value1","value2"); - 

var printArray = ArrayName.join(" - ");  - note: .join("[can be any separator for the output you want]") default = ,

document.write(printArray);

OUTPUT:
value1 - value2
0 william appiah-dankwah · March 30, 2015
Yeah it does not work iv tried that format already 
0 michael walker · March 30, 2015
try maybe instead of arrayName.join() how about the toString method??
0 william appiah-dankwah · March 30, 2015
is it hard to do an array with images?
0 william appiah-dankwah · March 30, 2015

function Yellow(){
var look = document.getElementById('Plane');
var List = new Array(); 
 
 List[0] = new Image;
 List[0].src = "pic/photo-1.JPG";
 List[1] = new Image;
 List[1].src = "pic/photo-2.JPG";
 List[2] = new Image;
 List[2].src = "pic/photo-3.JPG";


look.innerHTML += List[0];


}



any ideas?

0 Sho Carter · April 5, 2015
Of course i noticed that, and that's because of syntax errors, and in my code, you can add another image in the array, and loop over that....quite straight forward actually, and yes, it can also run over a loop over a few second interval...i can do that too, but depends on if it's what you wanted.
0 oluseyi obafemi · April 5, 2015
Provide a function called findWordSize that takes as arguments an array of String
and a number (length of word) and returns -1 if the a word of length equal to the
number, provided in the argument, is not found; otherwise returns the index of the
word which has length equal to number provided in the argument.
For example if the array is {“Program”, “Array”, “Code”, “Algorithm”, “Loop”} and the
number argument is 5, then the function will return 1, which corresponds to the
position of the word “Array” which is of length 5. Can anyone help to write the code for this question please. Cheers
0 william appiah-dankwah · March 31, 2015

Function Name(){

var Image Array
Image[0] = new Image;
Image[0].src = "pic/photo.JPG";

for(i = 0;i < 5;  i++){
var plane = document.getElement.ById('like');
plane.appendChild(Image[0]);
}



why isnt the loop working for this? 
-5 Ethan Fraser · June 11, 2014

var arrayName = new Array();

arrayName[0] = "String 1";
arrayName[1] = "String 2";
arrayName[2] = "String 3";
arrayName[3] = "String 4";
arrayName[4] = "String 5";

for (var i = 0; i < arrayName.length; i++) {
console.log(arrayName);
}



OR


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

for (var i = 0; i < arrayName.length; i++) {
console.log(arrayName);
}




Both can be used to display the contents of an array.

Javascript

107,257 followers
About

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

Links
Moderators