how to run javascript program

 
0
 

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?

 
0
 

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.

 
0
 

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

 
0
 

and to include js file in your pages

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

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

 
0
 

how to run javascript program

 
0
 

How to run a java script program

 
0
 

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>
 
0
 

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.

 
0
 

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! :)

 
0
 

*.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>
 
0
 

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")

}
You
Post:
Start New Discussion
Tags Related to this Article