0

Can anyone help me? I'm trying to call a JS file but is not working. I'm a newbie and really don't have any idea why.

<html>
  <head>
    <title>Stack</title>
    <meta charset=utf-8>
    <script>
      var fruits = new array();

      fruits[0] = "Apple";
      fruits[1] = "Strawberry";
      fruits[2] = "Orange";

      for(i=0; i<3; i++){
        document.write(fruits[i]+"</br>");
      }

      </script>
</head>
<body>
  <div>JavaScript</div>
</body>
</html>
1
  • 2
    Additionally to the other answers, use document.write inside the body and not in the head element Commented Mar 10, 2017 at 23:59

4 Answers 4

3

Array instead of array

<html>
      <head>
        <title>Stack</title>
        <meta charset=utf-8>
        <script>
          var fruits = new Array();

          fruits[0] = "Apple";
          fruits[1] = "Strawberry";
          fruits[2] = "Orange";

          for(i=0; i<3; i++){
            document.write(fruits[i]+"</br>");
          }

          </script>
    </head>
    <body>
      <div>JavaScript</div>
    </body>
    </html>
Sign up to request clarification or add additional context in comments.

Comments

3

Case sensitive boss

<script>
      var fruits = new Array();

      fruits[0] = "Apple";
      fruits[1] = "Strawberry";
      fruits[2] = "Orange";

      for(i=0; i<3; i++){
        document.write(fruits[i]+"</br>");
      }

      </script>

Comments

0

case sensitive:

<script>
              var fruits = new Array();

              fruits[0] = "Apple";
              fruits[1] = "Strawberry";
              fruits[2] = "Orange";

              for(i=0; i<3; i++){
                document.write(fruits[i]+"</br>");
              }

</script>

Comments

-1

Define the array like this

var fruits = [];

Or do this

var fruits = ['Apple', 'Strawberry', 'Orange'];

1 Comment

Although in this case it solves the problem, this is not the answer to it, as it doesn't explain what the problem was (lowercase array, document.write in head etc.)

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.