Category: Computer programming

  • addEventListener()

    The addEventListener() method allows you to add an event to an HTML element in JavaScript. Although the example used often shows this function being used to add a response of a ‘click’ event to a button, there is an easier way by using the ‘onclick’ property. This is the typical way to use a button:…

  • Writing more complex code

    When you first start learning to program, you are often motivated by a desire to create a specific program, like a game. But writing larger programs can be frustrating due to the number of errors and your lack of progress. I discuss how to develop you code step-by-step in order to achieve early success and…

  • If statements

    In JavaScript, if statements are written like this: This is one of the main ways that we use to get a program to make a decision based on input and do something different than it would otherwise do. When the program reaches the if statement, it will determine if the condition is true or false.…

  • Running a JS function with an HTML button

    This short tutorial shows how to run a function written in JavaScript when a button is pressed. The Code How the code works The HTML code has three tags: The JavaScript code defines one function, called buttonClick. The function contains a single line of code, which is run when the button is pressed. The function…

  • Adjusting the look of a hyperlink

    In HTML, a hyperlink is specified by the tag <a>. Here is an example: By default, the text in a hyperlink is blue and underlined. However, you can use CSS to change the appearance of a hyperlink. For example, This will change the text of the hyperlink be red (color) and to NOT be underlined…

  • setInterval()

    setInterval is a JavaScript command which takes two parameters. The first is the name of a function and the second is the time interval, in milliseconds, that this function should be repeatedly called. For example: In this code, setInterval calls the function ‘update’ every 10 milliseconds. The function increases the variable i by 1 and…

  • Using a textbox in HTML

    A textbox in HTML looks like this: The code for this looks like: When the enter key is pressed, the getInput() function will be run. In order to use the data entered into the textbox, you look at the value property like this:

  • Arrays

    An array in JavaScript is a variable containing multiple values. Arrays are indexed from 0 to n-1. By using a for loop, you can iterate through the array’s values without needing to list each value individually. Proper formatting makes an array’s structure easier to understand. Arrays are fundamental in JavaScript programming.

  • G-code

    What is G-code? G-code is the most widely used CNC and 3D printing programming language. It is used to provide commands for controlling the movement of tools as well as controlling the temperature of the 3D printer. The discussion below will focus mostly on using G-code for 3D printing. Syntax Each line of G-code contains…

  • Spirographs 3

    This is the third in a multi-part series on spirographs. It might be helpful to review part 1 and part 2 first. Review In the first two parts, I discussed the parametric equations for drawing a spirograph and rewrote these equations using coefficients that can vary independently to adjust the size of the design, the…