Code## Question
The following HTML code includes a script to alert a message. However, the alert is not working when the page loads. The script is linked to an external JavaScript file. How can I fix this issue and make the alert work?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>replit</title>
</head>
<body>
<div id="arjun">
<p>Lorem ipsum dolor, sit amet consectetur adipisicing elit. Vero aliquam deserunt minima, tempora iure amet rem accusamus, ea explicabo tempore saepe voluptas optio. Veritatis blanditiis magni molestia facilis distinctio! Ipsa!</p>
</div>
<!-- <script>alert('arjun is great')</script> -->
<script src="script.js" type="text/javascript"></script>
</body>
</html>
<!-- External Js code-->
alert('Arjun is Great');
Additional information
The script inside the HTML file works fine when uncommented. When linked to an external JavaScript file, the alert does not work.
2
Answers
I believe your code is fine, but if the JS file doesn’t work, make sure to follow these steps:
1.Check the file path
2.Clear your browser cache, as it can cause issues
3.Ensure that your JS file has a
.js
extension4.Make sure there are no typos in the code
I tried your code and as @disinfor and @ray in the comment suggested the browser is not running your JavaScript file because the
type
attribute is spelled wrongYou can either correct the spelling from
text/javasscript
totext/javascript
(the same way it is in the code version you shared) or remove the type attribute altogether