Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Kate Plowman
732 PointsJavascript - making an alert box show up in browser
My alert box won't show up in my browser, after the alert box linked to in my file, scripts.js.
(Code appears in head section of an html file.)
Real apologies - I'm sure it's a very basic question... `` <script src="scripts.js"); </script> <script> alert("Kate"); </script>
2 Answers
Samuel Glister
12,471 PointsHi Kate,
In the this instance if you want an alert to appear when your page loads you will need two basic files.
Index.html & script.js (you can also have a main.css if you would like to add styling)
The script will need to be located inside a local js folder and the index.html would need to sit outside the js folder on it own. (main.css would need to be located inside a css folder)
Then your index.html should like..
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/main.css">
<title>JavaScript Basics</title>
<script src="js/script.js"></script>
</head>
<body>
</body>
</html>
Then script.js should look like...
alert("kate");
This should then bring up the alert box with kate inside it when you load the page.
I hope this helps.
Abhishek Bhardwaj
589 PointsHow i can design alert box or customize alert box.?
Kate Plowman
732 PointsSamuel, thanks so much!
It works a treat now - so thanks again!
Samuel Glister
12,471 PointsNo problem, if you could mark my answer as the best answer that would be much appreciated.
Kate Plowman
732 PointsKate Plowman
732 PointsSorry, just learning.
This is the code I wanted to display.
Thanks for your help.