0

My current code is (inbetween the header and body tags, etc):

<script>
    var products = ["Printer", "Router", "Tablet", "Keyboard", "Javascript", "HTML"];
    products.sort();
    document.write(products);
    <br></br>
    document.write("The amount of products in the array is " + products.length);
</script>

However when I run this code nothing turns up on the webpage.

As stated, this is using dreamweaver, specifically dreamweaver CS5.

Can anyone tell me how to get a break between the lines displaying "document.write(products)" and the last document.write without all my code disappearing?

Thanks

ADreNaLiNe-DJ
  • 4,147
  • 3
  • 20
  • 34
Fen1209
  • 1
  • 1
  • 1
    Why do you have `
    ` within script? That shouldn't be there
    – mai May 24 '16 at 08:40
  • 1
    _document.write without all my code disappearing_......that's why `document.write()` should not be used. – Jai May 24 '16 at 08:41

1 Answers1

2

Usually you shouldn't use document.write unless you know exactly what you are doing, try to do something like this instead:

<div id="output"></div>
<script>
  var products = ["Printer", "Router", "Tablet", "Keyboard", "Javascript", "HTML"];
  products.sort();
  var el = document.getElementById('output');
  el.innerHTML = products.join(', ') + '<br>' 
    + "The amount of products in the array is " + products.length;
</script>
andlrc
  • 41,466
  • 13
  • 82
  • 108