Instruction
1
JavaScript runs within your browser, so all that is needed for writing and execution, is already in the computer. As a working tool of the programmer will use a plain text editor - Windows Notepad. This is enough to create a simple script, but, of course, for permanent programming it is better to use a specialized editor.The first step: in Notepad, create a new document to record the instructions to the browser.
2
Now you can start writing code instructions. The browser understands more than one language - for example, for the page markup language is HTML (HyperText Markup Language "hypertext markup language"), and to further describe the appearance of page elements - CSS (Cascading Style Sheets - "cascading style sheets"). To give the executor of the script to understand that this part of the source page is written in JavaScript, all instructions should be placed inside opening and closing tags:<script type="text/javascript">
...
</script>Instructions for the browser are called by the operators of the language. For example, the instruction to read and memorize for use later in the script the current date and time of the computer looks like this:var aTime = new Date();Now the object contains data aTime on the date and time and, if necessary, they can be retrieved and processed. Other manual - printed in the page body or a message looks like this:document.write("any message");note - there is an object named "document", it is not necessary to create, this happens automatically. It is a virtual image of the current page. From this object you can retrieve information about the page and can implement different transformation - for example, in this line of code you write is recorded in the document the text "some message".Now engage in the scenario of both these lines - write on the page current time:document.write ("the Current time" + aTime.getHours() + ":" + aTime.getMinutes());Here a simple operation of addition (+) you held up four constituent parts of the print string. The final your simple script would look like this:<script type="text/javascript">
var aTime = new Date();
document.write ("the Current time" + aTime.getHours() + ":" + aTime.getMinutes());
</script>
3
Final step: save the script with file extension html or htm (for example, timeJS.html). To see what you got, open the file in browser, just click it double click.