iFocus.Life News News - Breaking News & Top Stories - Latest World, US & Local News,Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The iFocus.Life,

Basic JavaScript Tutorial

104 151
    • 1). Create a new text file in the same directory as the Web page you want to use it in. Name it "myJavaScript.js."

    • 2). Open the new JavaScript file in a plain text editor like Notepad.

    • 3). Copy and paste the following code into the blank file. It's a "for" loop that declares a variable called "j," and sets j equal to 0. It compares the value of j to 10, and if j is less than 10 it keeps executing the code. At the end of every loop it adds one to the value of j. This will make an message box pop up with the value 0, and then 9 more boxes with the number growing from 0 to 1 to 2 all the way to 9:

      for (var j = 0; j < 10; j++) alert (j);

    • 4). Save the Javascript file.

    • 5). Copy and paste the following code into the head of your HTML document. This is a script HTML tag that tells the Web page to load a JavaScript file named "myJavaScript.js," which is the file you just created:

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

    • 6). Open the HTML document in your favorite Web browser to see the script pop up 10 messages boxes with the numbers 0 through 9.

Subscribe to our newsletter
Sign up here to get the latest news, updates and special offers delivered directly to your inbox.
You can unsubscribe at any time
You might also like on "Technology"

Leave A Reply

Your email address will not be published.