• Work Page
  • Main page

    Setting up a new page on this site:

    1. Create a new HTML file in the html directory, i.e. yourname.html
    2. We will create a link to the page in index.html: "Alexa's Page"
    3. Add head and body elements to the page (copy head from main page, change title)
    4. You can put javaScript directly in your page, but best practice tends to be to put it in a separate file
    5. So, create a file with a .js extension and save it in the 'scripts' directory
    6. Put a link to your .js file just before the body closing tag (see source for this page for syntax)
    7. You can test if your .js file is loading by adding an alert line to it, i.e. alert("some text"). If the .js is loaded/working the alert will fire when the page loads
    8. Add html to the .html page and javaScript to the .js page, add, commit and push to GitHub for testing your code
    9. If desired you can also add a css style page to the styles directory, this file should have a .css extension

    Using JavaScript:

    1. JavaScript is a scripting language originally designed for adding coding elements to web pages
    2. It is mostly used in conjunction with html and css, though its use has expanded rapidly into other areas
    3. All modern browsers have a built-in JavaScript engine, so no local instalation is required, just a web server to show your pages
    4. JavaScript syntax is similar to but not identical with Java: Java Syntax Wiki
    5. Lines of code are terminated by semicolons (actually sometimes optional, but recommended for clarity), braces/curly brackets deliniate blocks of code
    6. Variables are not typed, can be declared with keyword var, initial assignment of value is not requried, scoping is similar to Java
    7. Typically code is event driven, i.e. responds to mouse clicks/key strokes, i.e. myButton.onclick = function() { 'do something' }
    8. In order to interact with html elements, jS vars must be linked to the desired element(s)
    9. One way to do that is with a querySelector function, which you can see on the main.js page
    10. This can get cumbersome, especially in complex pages with many dynamic elements. The jQuery library was developed to simplify this process (see below).

    Linking js variables to html objects using jQuery:

    P5 (Java Script Processing Code) Examples Below