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 trialA X
12,842 PointsJavascript Basics Syntax Question on Challenge & Question about Code Challenge Behavior
I'm working on one of the early Javascript challenges (the one using shout.js), and I'm more interested in why the syntax is the way it is. I'm use to other language formats looking more like:
<html><img src= " "></html>
whereas in Javascript it looks like this:
<script src = "shout.js" ></script>
Why does Javascript allow the src (source) inside the beginning tags (I'm sure I'm using the wrong vocab word to describe what script is called)....
I also noticed something curious that I've never experienced before when doing code challenges with Javascript, that the program actually runs on my browser. Why is the code "activating" (again I'm probably off on the vocab) in Javascript but not in say HTML, CSS, SQL, or Java?
1 Answer
Damien Watson
27,419 PointsHi, the first example you provided is an image to be displayed inside html so you are saying import the image at location 'src' into the page.
<img src="...">
The second example is doing a similar thing, importing the javascript located at 'src' into the page.
<script src="shout.js"></script>
Coding Javascript in the page, you would not have the 'src' because you are not importing the javascript.
<script>
alert("Example");
</script>
I have also noticed that the code runs, I believe it to be a by product. In the challenge the code is loaded in, because it is loaded, it executes (runs).