Skip to content

Latest commit

 

History

History
120 lines (71 loc) · 3.43 KB

File metadata and controls

120 lines (71 loc) · 3.43 KB

JAVASCRIPT HELPS

ACCESS CONTENT

MODIFY CONTENT

  • You can use JavaScript to add elements, attributes, and text to the page, or remove them

PROGRAM RULES

You can specify a set of steps for the browser to follow (like a recipe), which allows it to access or change the content of a page. For example:

REACT TO EVENTS

You can specify that a script should run

when a specific event has occurred. For example, it could be run when:

  • A button is pressed
  • A link is clicked (or tapped) on
  • A cursor hovers over an element
  • Information is added to a form
  • An interval of time has passed
  • A web page has finished loading

Access the content of the page

Modify the content of the page Program rules or instructions the browser can follow React to events triggered by the user or browser

  • SLIDESHOWS

  • FORMS

  • RELOAD PART OF PAGE

  • FILTERING DATA

  1. . The script is triggered when the button is clicked.
  2. It collects the name entered into the form field.
  3. It checks that the user has entered a value.
  4. If the user has not entered anything, a message will appear telling them to enter a name.
  5. If a name has been entered, calculate the cost of the sign by multiplying the number of letters by the cost per letter.
  6. Show how much the plaque costs.
  • A script is a series of instructions that the computer can follow in order to achieve a goal. Each time the script runs, it might only use a subset of all the instructions.
  • 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).

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

Expressions rely on things called operators; they allow programmers to

create a single value from one or more values.

JavaScript contains the following mathematical

operators, which you can use with numbers. You may remember some from math class.

There is just one string operator: the+ symbol.

It is used to join the strings on either side of it.


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

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

Sometimes a function needs specific information to perform its task. In such cases, when you declare the function you give it parameters. Inside the function, the parameters act like variables.

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

Some functions return information to the code theat called them. for example, when they perform a calculation, they return the result.