0

This DOES WORK in other scripts I have written, but not here. Why? Other scripts I have written have been able to display the entire array, and were able to display 1-2-3 levels deep. ie Original[0] / Original[0][0] Am I missing something VERY simple?

Winning answer HERE: How can I create a two dimensional array in JavaScript? Works fine?

<html>
<head>

<script>
Original = [
[1,2,3,4,5,6,7,8,9,0],
[0,9,8,7,6,5,4,3,2,1],
[q,w,e,r,t,y,u,i,o,p],
[a,b,c,d,e,f,g,h,i,j],
];

function TestFunction(){
alert(Original);
}


</script>
</head>
<body>
<button onClick = TestFunction()>Test</button>
</body>
</html>
0

2 Answers 2

3

The problem was that you have a bunch of undeclared variables. In an array, strings must be enclosed in quotation marks.

Original = [
[1,2,3,4,5,6,7,8,9,0],
[0,9,8,7,6,5,4,3,2,1],
['q','w','e','r','t','y','u','i','o','p'],
['a','b','c','d','e','f','g','h','i','j'],
];

Here is an updated fiddle

http://jsfiddle.net/4fmtqou2/

Sign up to request clarification or add additional context in comments.

2 Comments

Ahh, ok, good. I was in too big of a hurry. This was actually a prep question for the next one,.
jsfiddle.net/RonK/hgtxzkrs/2 Here is more what the TOTAL problem was. But could not get even the pieces to work first.
2

You should quote your "q","w","e" ... characters in the array.

2 Comments

Yep, otherwise they are just undefined variables. Fixing this by wrapping them in quotes fixes the problem
innerHTML throws out an "undefined" at this point. I wish alert would do the same... wait... Has anyone seen it? thinking back, I swear I'd seen it before.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.