not working as expected events via HTML can't be called in script

Viewed 34

HTML:

<body>
  <script type="module" src="./script.js"></script>
  <div>Welcome to my first html page...</div>
  <div id="username">Another div tag</div>
  <p>This is a paragraph</p>
  <h1>Working on JS</h1>
  <button onclick="firstFunction()">Click</button>    
</body>

J/S:

function firstFunction() {
  console.log("Hurry")
}        

Getting error:

Uncaught ReferenceError: firstFunction is not defined

    at HTMLButtonElement.onclick (index.html:17)

onclick @ index.html:17

What might be the cause of this error?

1 Answers

Don't import the js script as module. use the following code instead :

<script src="./script.js"></script> `
Related