From the course: HTML, CSS, and JavaScript: Building the Web

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Creating functions

Creating functions

- [Instructor] Today, we're going to talk about functions in JavaScript. Functions are one of the most important concepts in programming. They allow us to group a set of instructions into a single unit that can be executed whenever we need it. Think of a function as a blueprint for a home improvement project. The blueprint contains all the instructions and measurements you need to follow to complete the project. Instead of figuring out the steps and measurements every time you want to do a similar project, you just refer to the blueprint. Similarly, instead of writing the same code multiple times, you write a function and call it whenever you need to perform a similar task in your program. Here in our script.js file, we're going to create a new function called dragElement. This function will take an HTML element as an argument, which is defined as terrariumElement here. This function that I just created here will take an HTML element as an argument and make it draggable. The…

Contents