I am trying to run a function in my JavaScript code. I'm trying to create two arrays, one with arabic words and one with the translated words in english, where corresponding words in each array have the same index. The purpose of the function is so that I can add an arabic word and its translation simultaneously.
The function doesn't run when I call it, and I have determined that the fact I am passing parameters in the function is what's causing it to not run. Why does this happen and how can I get the function to run? The script is in the <body> of the HTML.
This is my code:
var arabic = [];
var english = [];
function addToArrays(arabic, english) {
arabic.push(arabic);
english.push(english);
}
addToArrays("string1", "string2");
-
3I've mapped every word in the english language to foo or bar and will attempt to answer your question... Foo foo bar foo bar bar foo foo. Bar bar bar, foo foo bar foo. Foo bar?mVChr– mVChr2012年06月04日 02:25:04 +00:00Commented Jun 4, 2012 at 2:25
-
@mVChr - Hello world hello world world hello hello hello world world hello hello. World hello hello world world hello, world?Derek 朕會功夫– Derek 朕會功夫2012年06月04日 03:19:27 +00:00Commented Jun 4, 2012 at 3:19
1 Answer 1
Your parameter names are override your arrays. So what you need to do is rename your parameters. Something like this should work.
var arabic = [];
var english = [];
function addToArrays(a, e) {
arabic.push(a);
english.push(e);
}
addToArrays("string1", "string2");
3 Comments
arabic.push(arabic) is pushing the string onto itself - not onto the array. Thank you!