user3426207
user3426207

Reputation: 13

How to run a Javascript program from sublime text edit 2 to a web browser?

I am new to programming and am having trouble trying to open my Javascipt program to a web browser for testing. How is this done through Sublime Text Edit? I don't see any option for running to a browser. I can go to build then run but it all complies at the bottom of the screen. So how is it run directly to chrome?

Thank you

Upvotes: 1

Views: 2171

Answers (1)

Mikko Ohtamaa
Mikko Ohtamaa

Reputation: 83556

Browsers load HTML pages. In HTML page you have an option to load and execute JavaScript code via <script> tag.

  1. Create a HTML page

  2. Put it to the same folder with your .JS file

  3. In HTML have a <script> tag that loads your code:

    <html>
    <head>
    <script src="myjsfile.js"></script>
    </head>
    <body>
    </body>
    </html>
    
  4. Open this HTML file in Chrome (drag and drop, double click, etc.)

(Note: Nowadays there are also command line JavaScript programs which are run with NodeJS, but they are not usually for programming novices).

Upvotes: 2

Related Questions