I have saved a javascript in notepad with an .htm extension. When I go to file then open and type in the file name, it just opens up a it as an address in the address bar. I want to run the program in internet explorer, how do I do that?

If the file is just a javascript file you have to save it with a .js file extension and then call it from an HTML page as JavaScript does not run on its own. It must be part of a webpage.

another think to keep in mind, if you take that script from somebody site it may not work properly/ at all because it need some data

Member Avatar for GreenDay2001

and to include js file in your pages

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

It seems that I can run the .js file from Windows. Just double click it.

how to run javascript program

Member Avatar for rajarajan2017

You can run the javascript by including within your html file or just include the External Javascript file within the html file.

<html>
<head>
<!-- Internal Javascript Function -->
<script language="javaScript">
//Write your javascript functions within this script tag
</script>
<!-- External Javascript Function -->
<script language="JavaScript" src="javascript.js" type="text/javascript"/>
</head>
<body>
</body>
</html>

is it possible to placing 3 div horizontally, and want to make it display & hide div on click. but rest of the div will be in full width as the page.

Using <script language="JavaScript" src="javascript.js" type="text/javascript"/> is not valid (as per the W3C) for 2 reasons. The first being that the script tag is a content element and must use a </script> to close the elements envelope. The second, if the script tag was a leaf (contentless) element, there must contain a space before the /> . Using language="JavaScript" has been deprecated.

The only exception to this is when using XHTML, and although using the script tag as a leaf element will parse correctly in most modern browsers, it will cause the page to break in older browsers. This lack of backward compatibility is the primary reason the W3C will ONLY validate the script tag as a leaf element when used in XHTML.

To prove this point, I have provided a srcipt tag test using standard HTML and a srcipt tag test using XHTML. The official W3C validator can be found at validator.w3.org site.

Lastly, your in page script must use type="text/javascript" to validate correctly. Again, using language="JavaScript" has been deprecated and is not necessary.

Hope this helps. Enjoy! :)

*.js files are run with a Javascript interpreter engine. All major browsers have such an engine, as well as most operating systems.

To run the *.js file in a browser, include a reference to the file in a <script> tag. These can be placed within the <head> or <body> tag.

Example:

<html>
    <head>
        <script type="text/javascript" src="path/to/javascript_file.js"></script>
    </head>
</html>

Alternatively, you can also run the *.js file from your operating system given you have a Javascript engine installed on it. One such engine is called "NodeJS". You can use it by calling "node" then the *.js file.

Example:

node javascript_file.js <options>

so i got my java to work using

<html>
    <head>
        <script type="text/javascript" src="/Users/SireLeon/Desktop/java sword.js"></script>
    </head>
</html>

but my console.log(s) aren't working, im a noob and trying to learn java here is my script so far:

var user = prompt("You see a Sword laying on the ground",  "Touch it, Kick it, Leave it").toLowerCase();
switch(user) {

    case 'Touch it'.toLowerCase():
        console.log("The Sword glows with a mysterious light")
        var fear = prompt("Do you fear the glow?", "yes or no").toLowerCase()
        var smart = prompt("Have you used a sword before" , "yes or no").toLowerCase()
        if (fear === 'yes' || smart === 'no')
        {
            console.log("The Sword turns red")
        }
        else
        {
            console.log("The Sword turns blue") 
        }
        break;

    case 'Kick it'.toLowerCase():
        var strong = prompt("Are you strong", "yes or no").toLowerCase()
        var where = prompt("where do you kick the sword" , "hilt or blade").toLowerCase()
        if (strong === 'yes' && where === 'hilt')
        {
            console.log("You kick the sword so hard, it flies into the darkness")
        }
        else 
        {
            console.log("Sword swings back around and cuts off your legs")
        }
        break;

    case 'Leave it'.toLowerCase():
        var will = prompt("Do you wish to fight","yes or no").toLowerCase()
        var fright = prompt("Do you fear the Sword","yes or no")
        if (will === 'no' && fright === 'no') {
            console.log("The Sword whipsers to you: You!! are the chosen one!")
        }
        else {
            console.log("Maybe one day, You'll understand")
        }
        break;

    default:
    console.log("The swords kills you, cause of your ignorance")

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.