Skip to content

Latest commit

 

History

History
78 lines (59 loc) · 3.71 KB

File metadata and controls

78 lines (59 loc) · 3.71 KB

how to Programming with JavaScript

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. *** 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. *

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. *

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. *

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

To approach writing a script, break down your goal into a series of tasks and then work out each step needed to complete that task (a flowchart can help).

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

EXPRESSIONS THAT JUST ASSIGN A VALUE TO A VARIABLE **EXPRESSIONS THAT USE TWO OR MORE VALUES TO RETURN A SINGLE VALUE ** Operatiors (Assignment , Comparision , Logical , String , Arithmetic) OPERATORS Expressions rely on things called operators; they allow programmers to create a single value from one or more values. ASSIGNMENT OPERATORS Assign a value to a variable color = 'beige'; The value of co 1 or is now beige. ARITHMETIC OPERATORS Perform basic math area = 3 * 2; The value of area is now 6. STRING OPERATORS Combine two strings greeting= 'Hi 1 + 'Mol ly'; The value of greeting is now Hi Molly. COMPARISON OPERATORS Compare two values and return true or fa 1 se buy = 3 > 5; The value of buy is fa 1 se. LOGICAL OPERATORS Combine expressions and return true or fa 1 se buy= (5 > 3) && (2 < 4); The value of buy is now true. JavaScript instructions

A script is made up of a series of statements. Each statement is like a step in a recipe. Scripts contain very precise instructions. For example, you might specify that a value must be remembered before creating a calculation using that value. Variables are used to temporarily store pieces of information used in the script. Arrays are special types of variables that store more than one piece of related information. JavaScript distinguishes between numbers (0-9), strings (text), and Boolean values (true or false). Expressions evaluate into a single value. Expressions rely on operators to calculate a value ##funaction## Declaring a Function

To create a Function,you give it a name and then write the statements needed to achieve its task inside tje curly braces. This known as a Function declaration

Calling a Function

Having declared the function , you can then execute all of the statements between its curly braces with just one line of coede , This is known as calling the function

Declaring Functions That need information

Sometimes a functionneeds specific information to preform its task in such cases , when you declare the function you give it parameters inside the function , the parameters act like variables

Calling Functions that need information

When you call a function that has parameters,you specify the values it should use in the parentheses that follow its name. The values are called arguments and they can be provided as values or as variables

Getting a single value out of a function

Some functions return information to the code that called them For example , when they preform a calculation they return the result.

Getting multiple values out of a function

Functions can return more than one value using an array.