Skip to content

Latest commit

 

History

History
97 lines (64 loc) · 2.98 KB

File metadata and controls

97 lines (64 loc) · 2.98 KB

SCRIPT :

A script is a series of instructions that a computer can follow to achieve a goal.

A script are made up of instructions a computer can follow step-by-step.

A browser may use different parts of the script depending on how the user interacts with the web page.

Script can run different sections of the code in response of the situation around them.

WRITING A SCRIPT :

To write a script, you 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 want to achieve, and break that down into smaller steps

  1. DEFINE THE GOAL

First, you need to define the task you want to achieve. You can think of this as a puzzle for the computer to solve.

  1. DESIGN THE SCRIPT

To design a script you split the goal out into a series of tasks that are going to be involved in solving this puzzle. This can be represented using a flowchart.

  1. **CODE EACH STEP **

Each of the steps needs to be written in a programming language that the compu ter understands. In our case, this is JavaScript.

Note : Computers approach tasks in a different way than humans, so your instructions must let the computer solve the task prggrammatically.

EXPRESSIONS :

An expression evaluates into (results in) a single value. Broadly speaking there are two types of expressions.

  1. EXPRESSIONS THAT JUST ASSIGN A VALUE TO A VARIABLE In order for a variable to be useful, it needs to be given a value. As you have seen, this is done using the assignment operator (the equals sign). var color = 'beige'; The value of co 1 or is now beige.

  2. EXPRESSIONS THAT USE TWO OR MORE VALUES TO RETURN A SINGLE VALUE You can perform operations on any number of individual values (see next page) to determine a single value. For example: var area = 3 * 2; The value of area is now 6.

OPERATORS :

Expressions rely on things called operators; they allow programmers to create a single value from one or more values.

  1. ASSIGNMENT OPERATORS (=)

  2. ARITHMETIC OPERATORS (+,-,*,/,...)

  3. STRING OPERATORS (Combine two strings)

greeting= 'Hi 1 + 'Mol ly'; The value of greeting is now Hi Molly.

  1. COMPARISON OPERATORS (>,<,..)

  2. LOGICAL OPERATORS (Combine expressions and return true or fa 1 se) like and , or (&& , || )

FUNCTION :

  • Functions let you group a series of statements together to perform a specific task. If different parts of a script repeat the same task, you can reuse the function (rather than repeating the same set of statements).

  • If you are going to ask the function to perform its task later, you need to give your function a name. That name should describe the task it is performing. When you ask it to perform its task, it is known as calling the function.

  • Some functions need to be provided with information in order to achieve a given task. Fore xample, a function to calculate the area of a box would need to know its width and height. Pieces of information passed to a function are known as parameters.