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>
Community
  • 1
  • 1
Ronk
  • 215
  • 2
  • 11

2 Answers2

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/

Richard Hamilton
  • 25,478
  • 10
  • 60
  • 87
  • Ahh, ok, good. I was in too big of a hurry. This was actually a prep question for the next one,. – Ronk Oct 12 '15 at 20:23
  • http://jsfiddle.net/RonK/hgtxzkrs/2/ Here is more what the TOTAL problem was. But could not get even the pieces to work first. – Ronk Oct 12 '15 at 20:52
2

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

  • 1
    Yep, otherwise they are just undefined variables. Fixing this by wrapping them in quotes fixes the problem – Richard Hamilton Oct 12 '15 at 20:23
  • 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. – Ronk Oct 12 '15 at 21:51