I´m still new to javascript.For training purpose I have inserted part of a javascript(lines 23 to 31) code into my html file and it works the windows.alert and number 12 shows
But when i uncomment parts of it (lines 26 to 28) that javascript code doesnt work well again,the windows.alert and number 12 dont show
Is my initiation of the 2dimensional array wrong or am I only allowed to initiate that 2dimensional array within a function or external file ? For better readabilty i have shortened the html file.

<!DOCTYPE html>
<html>
<head>
    <title>Home</title>
    <meta http-equiv="Content-Type" content="text/html; charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="style.css">
</head>
<body>
    <header><h1 style="display:inline;position:relative;top:10%;">Deine Pizzeria</h1>
    </header>
    <p id="demo"></p>
    <section id="maincontainer"><div class="resize"></div>
        <section id="upleft" class="navilinks"><a href="index.html">Home</a>
        </section>
        <section id="upright" class="navilinks"><a href="speisemenue.html">Speisemen&uuml</a> 
        </section>
        <section id="downleft" class="navilinks"><a href="kontakt.html">Kontakt</a>
        </section>
        <section id="downright" class="navilinks"><a href="anfahrt.html">Anfahrt</a>
        </section>   
    </section>
    <script>

    window.alert(5 + 6);
    /*var pizzen = [["Mageritha",4.90],["Cardinale",5.90],["Salami",6.90]];
    var salate = [["Insalata Mista"],3.5],["Insalata Polo"],5],["Insalata Tonno"],5.5]];
    var suppen = [["Tomatencremesuppe"],2.8],["Knoblauchcremesuppe"],2.9],["Frittatensuppe"],3]];*/

    document.getElementById("demo").innerHTML = 5 + 7;
    </script>

</body>
</html>

Hi

The reason is that the arrays salate and suppen are not declared correctly. They should be declared in the same way as you have for pizzen:

    var salate = [["Insalata Mista",3.5],["Insalata Polo",5],["Insalata Tonno",5.5]];
    var suppen = [["Tomatencremesuppe",2.8],["Knoblauchcremesuppe",2.9],["Frittatensuppe",3]];

HTH

Still dont see where i declared salate and suppen differently. Can you pinpoint the problem ? Note: Comments run from line 26 to 28.

okay , i see what you mean. hope it solves the problem thx

When you create a 2 dimensional array, the syntax is:

var yourArray = [[1, 2], [3, 4]];

but in your example you have:

var yourArray = [[1],2],[3],4]]

So, where you have pizzen:

var pizzen = [["Mageritha",4.90],["Cardinale",5.90],["Salami",6.90]];

That is correct, but salate and suppen both follow the following format which is not correct:

var salate = [["Insalata Mista"],3.5],["Insalata Polo"],5],["Insalata Tonno"],5.5]];

Also, I should add, that if you are not already, use the developer tools available to you within your browser. Chrome has built in Developer Tools and I think Firefox does also although you can install the FireBug plugin if it does not. These help a great deal in finding issues like this.

maybe this way you will have a better overview of your error in variables "salate" & "suppen":

var pizzen = 
    [
        ["Mageritha", 4.90],
        ["Cardinale", 5.90],
        ["Salami", 6.90]
    ];

var salate = 
    [
        ["Insalata Mista", 3.5],
        ["Insalata Polo", 5],
        ["Insalata Tonno", 5.5]
    ];
var suppen = 
    [
        ["Tomatencremesuppe", 2.8],
        ["Knoblauchcremesuppe", 2.9],
        ["Frittatensuppe", 3]
    ];

watch out the oppening and closing of inner array literals.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.