How To Write A Script

Table of contents:

How To Write A Script
How To Write A Script

Video: How To Write A Script

Video: How To Write A Script
Video: How to Start Writing your Screenplay 2024, December
Anonim

In today's Internet, total interaction reigns - you have to try very hard to find at least some site that does not offer the visitor to do something and immediately get a response from the site. However, often we are not even offered to fill in or press anything - the page itself reacts to the movement of the cursor and, at times, you walk through the pages like through a minefield. All interactivity on sites is provided by scripts. These can be both scripts executed on the server and those executed on our computer. Let's try to write the simplest script to get an idea of what it actually is.

How to write a script
How to write a script

Instructions

Step 1

The word script itself literally means "script", that is, a description of the sequence of actions required to complete the task. The executor of this scenario can be either the corresponding module of the server software, or the browser on our computer. Since a browser, as opposed to a web server, is always at hand, let's write a script in a language that the browser understands - JavaScript. Any text editor is enough for this - a standard notepad is fine. Of course, for constant programming of scripts, you cannot do without a specialized editor. Such an editor greatly facilitates the routine work of writing scripts, leaving your head free for creativity.

Step 2

For a browser to read, understand, and execute a task, a script must be written and written according to rules known to the browser's built-in scripting language interpreter. The first line is to inform the performer that the script starts from this point. In JavaScript, this opening tag may look like this: And the closing tag looks like this: Between these two tags are instructions - language operators. For example, a set of instructions for the browser to print the current time in the format HOUR: MINUTE looks like this: var aTime = new Date ();

document.write ("Now" + aTime.getHours () + ":" + aTime.getMinutes ()); Here the first line var aTime = new Date () instructs the script executor to create a virtual object named "aTime". This object represents the current date and time. document.write () is a command to print in the page what is indicated in parentheses below, and the aTime.getHours () and aTime.getMinutes () commands instruct to retrieve the current hour and minute from the "aTime" object. The "+" operators concatenate the entire string to be printed onto a single line. When assembled, this simple JavaSript script would look like this:

var aTime = new Date ();

document.write ("Now" + aTime.getHours () + ":" + aTime.getMinutes ());

Step 3

It remains to save this code in a file with the htm extension or the html extension (HyperText Markup Language), the operating system will recognize the file type and transfer it for execution to the program that is assigned this file type - the browser. As a result, our script will be read and executed by the language interpreter and presented in the browser window as follows:

Recommended: