You can use editing tools on your device or within supporting software.
JavaScript can work with the user's (client) resources or server resources.
It is easy to learn the basics.
Step One: HTML & Scripts
Activity: Open up your text editor of choice and create a basic page (a basic note pad works great). Now I am going to teach you how to write on your webpage using JavaScript. Type the following into your text editor:
As you can see, our JavaScript instruction (document.write('Hello World!');) is added directly into your HTML by adding the <script> tag.
Now save the text file with an HTML file extension. Use the "save as" function for your text editor and change the filename from something like "New Text Document.txt" to "Hello World.html". Use the .html in place of the .txt, .doc, .rtf, etc... Open your newly saved file in a browser. If all went well "Hello World!" will display in your browser as HTML content. If not, perhaps set your computers folder options to show filename extensions. Javascript and 'filename changes' are not always available (by default).
To start off with, the <script type="text/javascript"> tag tells the browser that whatever comes between that tag and the coming </script> tag is script, and the type="text/javascript" tells it that it is JavaScript. Similarly, to use VBScript, you might use type="text/vbscript" instead of "text/javascript". For the purposes of this course, though, you should only ever need to use the JavaScript tag.
It is also important to note that the <script> tag is case sensitive. What this means is if you use lowercase letters in the tag, all the letters in the tag must be lowercase, and uppercase if you use any uppercase. For example, if you wrote
<ScRiPt TyPe="TeXt/JaVaScRiPt">
Not only would you waste a lot of time typing, but you would also confuse your browser.
You are probably wondering when I'm going to explain the rest of what you did. Well, document.write() is the JavaScript standard for writing text to the browser window. The 'document' clause refers to the HTML webpage (termed a document) as a whole; what follows ('.write()') is a command for the document object to carry out. In this case, you told the page to write the classic "Hello World" to the screen.
Comments
//(Brian Crowder) A 'Hello source-reader' contribution.
.
Step Two: Variables
One of the things JavaScript is used for is the manipulation of data. In JavaScript, pieces of data can be stored either in variables or arrays.
Variables are declared using the var keyword:
var numValue;
var textValue;
var binaryValue;
and can be given values when they are created:
var numValue = 3;
var textValue = "This is text.";
var binaryValue = true;
Multiple variables can even be declared at the same time:
var numValue = 3, textValue = "This is text.", binaryValue = true;
Variables in JavaScript are weakly typed, meaning that the types of individual variables are not determined by the programmer. Unlike many languages, JavaScript only provides a generic var rather than separate types for integers, floating point numbers, characters, and strings. For example, in the statement
var x = 0;
it is fairly obvious to any individual reading the code that x is a number. However, if the statement
x = x + "This is text that is probably not a number";
were to appear later in the code, JavaScript would change the variable to a text variable. This is one of the reasons that JavaScript is referred to as weakly typed; at any particular point in time, it is impossible to tell exactly what type a particular variable is.
varx="hello";vartowrite=(x=="hello")?"Hello world, again!":"Look at the state of that!"document.write(towrite);//The example results in "Hello world, again!" because x is "hello" and condition "Hello world, again!" is logically true.
</script><p>
Save the document as helloToo.html and open it in a browser.
Change the line var x = "hello" to var x = "punk" and use CRTL + S to save.
Run it in your browser.
</p></body></html>
Semicolons
JavaScript require semicolons to be inserted to end statements and expressions.[4] When you forget to add semicolon between commands, JavaScript adds it automatically so that it knows where to start the next command.
The rules of JavaScript automatic semicolon insertion are as follows:
When the next line starts with a closing braces } , closing the current block
When there is a return statement without a semicolon
When there is a break statement without a semicolon
When there is a throw statement without a semicolon
When there is a continue statement without a semicolon
When the final statement of the code is reached (The last line on the JavaScript file)
You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.