I am trying to do alert("clicked") when a button is pressed but I can't get it to work on visual studio code, it only works on codepen. I run the index.html in visual studio code using an extension called open in browser.
I tried copying the codes to codepen and it worked
<html>
<head>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<h1>Random dog Pictures</h1>
<img id = "photo" src = "https://i.pinimg.com/originals/68/6d/6f/686d6fc9d01def6b6f63acded53479bc.jpg" alt = "">
<button id = "btn">Get Random Dog Photo!!!</button>
</div>
<script src="randomDogPicture.js"></script>
</body>
</html>
var btn = document.querySelector("#btn");
btn.addEventListener("click", function() {
alert("clicked");
});
I expected it to display "clicked" but it doesn't do anything when I click the button.