Elements of a Web Project

See the Pen Example Code by LSU DDEM ( @lsuddem) on CodePen.

https://codepen.io/lsuddem/pen/MGMMXv

HTML file

<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

  </head>
  <body>
    <script src="sketch.js"></script>
  </body>
</html>

CSS file

CSS stands for “Cascading Style Sheets”, and is code that describes and controls the layouts of the HTML elements we code for in our “index.html” file. We will not be focusing much on editing and designing code for our CSS files throughout this course, so the CSS portion of every project we create can be extremely simplistic:

html, body: {  
 margin: 0;
 padding: 0;
}

JavaScript File

function setup() {
  createCanvas(600, 600);
  background(200);
 
}

function draw() {
 //nothing here yet!
  
}

  

Data Types

Throughout our projects, we will be using a variety of different data types in our code. Here is a quick explanation of common data types used in JavaScript:

  • Number
    • 1 2 3.25 4.01029814029841 5
  • String
    • some text
  • Boolean
    • true or false

Coding with Proper Syntax

function setup() {
  createCanvas(600, 600);
  background(200);
 
}

function draw() {
 //nothing here yet!
  
} 
  • Good code includes comments or short explanations of any complex elements involved so that others can learn from your work. This is also helpful to keep track of how your code works so that you can pinpoint exact lines or sections that may need to be fixed. When in doubt, always add comments into your codes. To leave comments in your JS file, add two / symbols before the comment you want to type:
//Here is a comment. This is only readable by you, not the browser

Longer comments that span multiple lines can be made like this:

/* Here is
a multi-line
comment. Neat!
*/

Using the Console

The console is a section of your code editor or browser that can be used when you want to get information on aspects of your code, or you want to see a log of any and all errors that have occurred in your project. You can also use the console to communicate with your code while it is running, which is helpful for checking on the current state of variables, the current color of shapes and objects, or to even double check that functions or events you designed are working properly.

See the Pen Example Code by LSU DDEM ( @lsuddem) on CodePen.

https://codepen.io/lsuddem/pen/OEmEpM