Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Basics_Writing Your Program

I on the second video. http://teamtreehouse.com/library/introduction-to-programming/basics/writing-your-program I am using Chrome as my browser and notepad as my editor. I have created and saved the .html & .js files in the same folder. I am able to open the .html file with my browser. I am able to open the developer/console tool but I am not able to see the message that is supposed to come from the .js file.

9 Answers

I figured it out. For some reason the script command was not loading into the element section of the developer tool. I changed from notepad editor to sublime text2 and then resaved and not it is picking up the .js file.

thanks for helping

Casey Clayton
Casey Clayton
16,708 Points

Can you paste the code from your .js file here please?

console.log("Hello from myscript.js"); console.log("Hello again!");

Casey Clayton
Casey Clayton
16,708 Points

Ok, it looks right so I am going to guess that you have not linked to this file in your html which is done like so.

In your index.html file near the bottom of your file before the closing body tag link to it like this.

<script type="text/javascript" src="myscript.js"></script>

This should fix the problem.

I did not have it linked. I linked the file into the index.html but that still did not work. Could it be something not set up right in Chrome? On the first video I entered JavaScript directly into the console section of the tool developer and everything worked fine. But now using the index.html file & the myscripts.js file nothing is showing up in the console section when I refresh the browser.

Casey Clayton
Casey Clayton
16,708 Points

Ok make sure you save both index.html and myscript.js and then refresh the browser. Every time you update your code in your js file you must save it and then refresh the page so that it reloads the new saved file. Also make sure your console.logs are on a separate line like this.

console.log("Hello from myscript.js"); 
console.log("Hello again!");

double checked and the .js file was already linked so that isn't the problem.

Yes, I am saving each file each time before I refreash.

Casey Clayton
Casey Clayton
16,708 Points

Ok I just setup a test page and got it to work fine. Here is my exact code, this should work for you if not it is a problem with chrome.

HTML:

<!DOCTYPE HTML>
<html>
<head>
<title>Javascript Test</title>
</head>
<body>
<h1>Testing javascript console.log</h1>
<script type="text/javascript" src="myscript.js"></script>
</body>
</html>

Javascript:

console.log("Hello from myscript.js");
console.log("Hello Again!");