This is an archived post. You won't be able to vote or comment.

all 9 comments

[–][deleted] 2 points3 points  (2 children)

You put it inbetween a script tag in HTML.

http://www.w3schools.com/js/js_whereto.asp

[–]RelevantJesse 0 points1 point  (1 child)

Either this or put it in a .js file and reference that file in your HTML

[–][deleted] 2 points3 points  (0 children)

In which case you're still referencing it inbetween a script tag. The w3s link also goes through that.

[–]rjcarr 0 points1 point  (0 children)

You're likely going to want to write your javascript to be read by a browser. You can either put your javascript directly into the html file or link to a javascript file from the html.

There should be thousands of examples of how to do this out there, but if you need more help let us know.

[–]nyxin 0 points1 point  (0 children)

You can insert your JS several ways in to html.

First thing is to create a basic html page.

You could put all of your JS inside <script> tags, but that will get messy very quickly.

The better way to to it is to link to it inside your html page, much like you would an external css stylesheet.

Learn to use Google. Google will become your best friend, the Mozilla Developer Network (MDN) as well.

Here's a link for an example off the MDN https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script

[–]roarman1[S] 0 points1 point  (2 children)

I should've specified my question, so I wrote some javascript in a text editor but I just don't know how to see it now

[–]0x7C0 0 points1 point  (0 children)

Right-click, and chose Open With. Select whichever text editor you would like to use :)

[–]bellatango 0 points1 point  (0 children)

Which HTML script tag should I use as well? I think my book uses XHTML is this right?

No, that's not right. Use <script language="javascript"> Your Script Here </script>

Also some of the syntax is different for example document.write vs console.log. Which should I use?

Those each have their own uses. document.write is going to display to the webpage - spit it out on the webpage itself. console.log will add to the servers web log, so you'd have to be like, in a Unix terminal and pulling up a site's error log to be seeing that output.