0

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>

Edited by samson.oba.77

3
Contributors
6
Replies
13
Views
2 Years
Discussion Span
Last Post by Troy III
1

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

0

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

1

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]];
1

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.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.