Skip to content

Latest commit

 

History

History
122 lines (79 loc) · 3.11 KB

File metadata and controls

122 lines (79 loc) · 3.11 KB

Read: 04a - Dynamic web pages with JavaScript

in the web bages you can fit together with the HTML and CSS in your web pages

  • HTML ONLY Starting with the HTML layer allows you to focus on the most important thing about your site: its content. Being plain HTML, this layer should work on all kinds of devices, be accessible to all users, and load quite quickly on slow connections

  • HTML+CSS Adding the CSS rules in a separate file keeps rules regarding how the page looks away from the content itself. You can use the same style sheet with all of your site, making your sites faster to load and easier to maintain. Or you can use different style sheets with the same content to create different views of the same data.

  • HTML+CSS+JAVASCRIPT The JavaScript is added last and enhances the usability of the page or the experience of interacting with the site. Keeping it separate means that the page still works if the user cannot load or run the JavaScript. You can also reuse the code on several pages (making the site faster to load and easier to maintain).

CREATING A BASIC JAVASCRIPT

JavaScript is written in plain text, just like HTML and CSS, so you do not need any new tools to write a script.

A JavaScript file is just a text file (like HTML and CSS files are) but it has a . j s file extension, so save this file with the name add-content . j s

LINKING TO A JAVASCRIPT FILE FROM AN HTML PAGE

'You may see JavaScript in the HTML between opening <script> and closing </script> tags (but it is better to put scripts in their own files).'

PLACING THE SCRIPT IN THE PAGE

'You may see JavaScript in the HTML between opening <script> and closing </script> tags (but it is better to put scripts in their own files).'

method javascript

JAVASCRIPT RUNS WHERE IT IS FOUND IN THE HTML When the browser comes across a <script> element, it stops to load the script and then checks to see if it needs to do anything.

how i do i rite for web pages?

  • It is best to keep JavaScript code in its own 'JavaScript' file.

  • 'The HTML' <script> element is used 'in HTML' pages to tell the browser to load the 'JavaScript' file (rather like the element can be used to load a' CSS' file).

  • 'If' you view the source code 'of' the page 'in' the browser, the 'JavaScript' will not have changed the' HTML,' because the script works 'with' the model 'of' the web page that the browser has created.

basic javascript instraction.

'A script is a series of instructions that a computer can follow one-by-one 'Each individual instruction or step is known as a statement. 'Statements should end with a semicolon'

'JAVASCRIPT IS CASE SENSITIVE' 'JavaScript is case sensitive so hourNow means 'something different to HourNow or HOURNOW''

WHAT IS A VARIABLE?

A script will have to temporarily store the bits of information it needs to do its job. It can store this data in variables.

  1. Remember the value for width
  2. Remember the value for height
  3. Multiply width by height to get the area
  4. Return the result to the user