Disclaimer: I've been programming for all of fifteen minutes. I'm trying to follow along on Lynda.com's Programming Foundations class, but I can't seem to link my JS to my HTML. They're in the same folder.When I open the HTML file on my browser, I don't get the JS pop-up box that the dude in the video does. What am I doing wrong?
Here's my HTML file:
Simple Page
This is a very simple HTML page
And here's the JS file titled "script.js" in the same folder as the HTML file.
var name = prompt["What is your name?"];
alert["Hello, " + name];
asked Mar 28, 2016 at 19:20
5
It worked for me when I changed the quotation marks to straight ones. Copy and paste this:
Instead of this:
Let me know if it works.
answered Mar 28, 2016 at 19:44
user326964user326964
4241 gold badge5 silver badges13 bronze badges
2
Fix your quotes use " not “. The browser is unable to parse your html. Use the developer console to check for errors in the future.
answered Mar 28, 2016 at 19:44
Try this plunker. It has your code exactly [even same name script.js] except I changed the quote chars and it works perfectly. Use Plunker to test all your js.
//plnkr.co/edit/4Mw0RmWfblGp9U8gsuvx
Simple Page
This is a very simple HTML page
answered Mar 28, 2016 at 19:55
raddevusraddevus
7,4775 gold badges61 silver badges74 bronze badges
1
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.
Hey forum!
I'm having a lot of problems linking my JS file to my HTML file, and I can't figure out what's wrong.
I apologize in advance if my code doesn't post right. This is my first time asking a question on this forum....
This is just an excerpt from the bottom of my HTML code where the script tag is. I've verified[about 15 times] that the .js file name is spelled correctly and in the same folder as the HTML file.
© BC Webinations 2014 src="calc.js"
My JS is just a simple alert to let me know it's working, which it isn't...
Now, I'm aware that I didn't declare a "type" in the script tags, and that's because every time I do, the javascript returns a syntax error.
I'm expecting it to be just a stupid little typo or something....
Thanks guys!
-Brent C.
P.S. I'm running the latest Google Chrome with Ubuntu, if that means anything.
7 Answers
Jeff Busch November 8, 2014 2:14am
Hi Brent,
Change:
src="calc.js"
To:
Jeff
STAFF
Brent;
You need to put your src
assignment inside your script tag. should do the trick.
You can move it to a separate js
folder like Robert mentioned, that is a pretty common practice.
Happy coding, Ken
STAFF
not sure, but try putting your js into it's own subfolder that sits next to your html file, name the subfolder simply js, and then you link like this, src="js/calc.js"
hope that helps
Brent Cralley November 8, 2014 2:14am
Gave your suggestion a shot, Robert, and still no dice. From what you can see, all of my syntax is correct, right?
-Brent C.
Brent Cralley November 8, 2014 2:21am
Thanks for the help, guys! I knew it had to be something stupid that I just wasn't seeing. ;-]
Now, on the plus side, my script tag now accepts "type="text/javascript" without showing any syntax errors.
On the downside, it's still not showing any of my javascript in either the console or a pop-up alert window....
Brent Cralley November 8, 2014 2:36am
© BC Webinations 2014
alert["Help!"]; console.log["Help me!"];
Jeff Busch November 8, 2014 2:47am
With the code you have the html and javascript files must be in the same directory. Your code works on my computer.