-2

<script>
  let name = prompt("what is the name?");
  document.getElementById('assignmentName').innerHTML = name;
</script>
<div id="assignmentName"></div>

Why does this not work?

1 Answers1

0
<div id="assignmentName"></div>
  <script>
    
    let name = prompt("what is the name?");
    document.getElementById('assignmentName').innerHTML = name;
    console.log(name)
  </script>

There are two good ways to include the JavaScript.

  1. Create a new script.js. Copy & Paste <script src="script.js" defer></script> right in front of the closing </body> tag.

or

  1. Create a new script.js. Copy & Paste <script src="script.js" defer></script> right in front of the closing </head> tag.

In this both cases, defer is forcing the website layout to 100% and run the skript after.