Why html and js files are not linking?

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="array.css">
    <script src="arrayIn.js"></script>
    <title>Document</title>
</head>
<body>
    <div class="inputpart">
    <form class="" action="index.html" method="post">
        <input type="text" name="array[]" value="" /><br>
        <input type="text" name="array[]" value="" /><br>
        <input type="text" name="array[]" value="" /><br>
        <input type="text" name="array[]" value="" /><br>
        <input type="text" name="array[]" value="" /><br>
        <button id="btn" type="button" name="button" onclick="arrayIn()">Submit</button>
    </form>
</div>
</body>
</html>

js

function arrayIn() {
    document.getElementsById("btn").console.log("hello world");
}

I spot a few things here

The correct method is getElementById with no s

but also you don’t need that at all

You can have the function with the console statement like this

function arrayIn() {
  console.log("hello world");
}

now you should be able to see the hello world when the button is clicked

Thanks for replying, but it’s not working.

what is your updated code look like now?

I have tested it locally on my end and the console statements are showing up.

thank u so much,
I did a small mistake that’s y it was showing a error.
you are right . Now I got it correct.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.