JavaScript JavaScript Basics Hello, JavaScript! Add JavaScript to HTML

The script in script.js will cause an the alert, but doesn't when I write it into the index file, the second alert works

rel="stylesheet"> <script src="js/script.js"></script> <script> alert("Another message from inside index.html") </script>

3 Answers

Bob Swaney
Bob Swaney
11,848 Points

hello. what do you mean that it doesn't cause the alert when you write it into the index file? If you load up the HTML page and the .js file is causing the alert and the second alert is working, isn't that what you are looking for? if the alert from the .js file is firing, then you have it linked up to the HTML correctly.

mohamed adam
seal-mask
.a{fill-rule:evenodd;}techdegree
mohamed adam
Full Stack JavaScript Techdegree Student 11,884 Points

hello, does it work when in the html or when it is in the js file? may be you did not link up properly? take screenshot of the whole screen so we can have a look.

Stijn Vanthournout
Stijn Vanthournout
687 Points

I also only get the second alert "another message" to work. The first one doesnt run.