Script and javaScript

A Script is a set of instructions that a computer can follow to achieve a goal. You could compare scripts to recipes, handbooks and manuals. Depending on how the user interacts with the web page, a browser may use different parts of the script. To write a script, you would need to first state your goal and then list the tasks that need to be completed in order to achieve it. Start with the big picture of what you hope to achieve, break it down into smaller steps.

  • Define the goal
  • Design the script (algorithm, flowchart...)
  • Code each step

Define the goal Defining the goal is understanding what you expect your script to achieve.

Designing the script Once you've known the the goal of your script, you can work out the individual tasks needed to achieve it. Each individual task may be broken down into a sequence of steps. When you're ready to code the script, these steps can then be translated to individual lines of code.

Code each step Every step in the flow chart needs to be translated into a language the computer will understand and follow. Just like learning a new language, you need to get the grips with the vocabulary and syntax Because computers need different instructions compared to you and I, everyone who learns to program makes a lot of mistakes at the start. There are several ways to discover what might have gone wrong. Programmers call this debugging.

A computer solves problems programmatically. It would need explicit set of instructions. Each time the script runs, it might only use a subset of all the instructions.

Computers create models of the real world using data

In computer programming, each physical thing in the world can be represented as an object. Two of the same object, like 2 cars are considered by programmers as two instances of a car object. Each object can have its own: • Properties • Events • Methods

together, these create a working model of that object. Similar objects like two cars have same characteristics like speed, color, engine size. programmers refer to these as properties.

PROPERTY Each property has a name and a value and these tell you something about each individual instance of the object. property names of same instances of an object may be the same, but their values will most likely vary.

EVENTS As people interact with objects in the real world, these interactions can change the values of the properties in these objects. Events involve common ways in which people interact with each type of object. In driving a car, the driver will typically use two pedals. for instance clicking on a contact link on a web page could bring up a contact form. An event is the computer's way of sticking up its hand to say, "Hey, this just happened!"

METHODS Methods represent things people need to do with objects. They can retrieve or update the values of an object's properties.

When you use a method, you do not always need to know how it achieves its task; you just need to know how to ask the question and how to interpret any answers it gives you.

Computers use data to create models of things in the real world. The events, methods, and properties of an object all relate to each other: Events can trigger methods, and methods can retrieve or update an object's properties.

Web browsers are programs built using objects. The document object represents an HTML page.

In order to understand how you can change the content of an HTML page using JavaScript, you need to know how a browser interprets the HTML code and applies styling to it. 1 Receive a page as a HTML code 2 Create a model of the page and store it in memory 3 Use a rendering engine to show the page on the screen.

All major browsers use a JavaScript interpreter to translate your instructions (in JavaScript) into instructions the computer can follow. HTML, CSS and JavaScript Where possible, aim to keep the three languages in separate files, with the HTML page linking to CSS and JavaScript files.

A JavaScript file is just a text file (like HTML and CSS files are) but it has a ".js" file extension. When you want to use JavaScript with a web page, you use the HTML tags (but it is better to put scripts in their own files).