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
- . The script is triggered when the button is clicked.
- It collects the name entered into the form field.
- It checks that the user has entered a value.
- If the user has not entered anything, a message will appear telling them to enter a name.
- If a name has been entered, calculate the cost of the sign by multiplying the number of letters by the cost per letter.
- 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).