Beginning Programming: Creating Your First Project

0
15

If you’re new to programming, this post is for you. In this blog post, we’ll be discussing the steps of creating your first code project, as well as how to make it look professional with CSS and HTML5. We’ll cover the basics of basic programming suggested by Something With Numbers such as variables and loops as well as JavaScript and its unique use of functions. By the end of this article, we’ll have shown you how to create a very tiny 2D game using just HTML5 and JavaScript!

Not into coding? That’s fine too! We’ll still bring in CSS and HTML5 because these can help you achieve professional quality aesthetic design with little effort due to how simple they are.

Desktop, Computers, Screens, Monitors

Getting Started

If you don’t already have one, create your own free account on Bitbucket which is a code hosting site like github. You can use either. Both are free. I’ve chosen Bitbucket in this post because I personally like it better, but feel free to choose whatever you want.

Let’s start with the introduction to programming! We’ll be using the JavaScript programming language which is currently one of the most popular languages out there along with Java and PHP (arguably). JavaScript is used by large corporations such as Google and Facebook, so it’s definitely worth learning how to use since you’ll be able to get jobs much easier.

Variables and Loops

Variables is a programming concept that allows you to store information. What kind of information? Well, it’s up to you! If you want to store your dog’s name (because clearly he or she is the most amazing thing in the world), how much money you have, or even if you want to store a table of websites – it’s all possible with variables. What we’ll be covering in this article is the creation and use of numerical and string variables (we’ll cover why these two types of variables exist below).

Format:

To create a variable in JavaScript, simply use the following format: name_of_variable = value_you_want_stored . It’s that simple. For example, to create a variable called mydog , all you need to do is type the following line of code: mydog = “Buster” .

But what if you want different variables? Easy. Just copy and paste the code above onto the bottom of your script line (so that it’s on more than one line) and just change mydog to another name that you prefer. However, if you want multiple instances of the same variable (eg. 100 of your dog), copy and paste it more than once on the bottom of your script (in exactly the same format) and change each instance of mydog to whatever new name or number you prefer. (Hint: You can add code such as for (var i = 0; i < 100; i ++) to the script line).

Now you’re probably thinking: “Well, what about strings?”.

If you’ve played around with HTML and CSS, you’ve probably encountered strings. What are strings? You can think of it like this: A string is a series of characters (ie. letters and numbers) that we use to define words and phrases. 

How can we define words and phrases? 

Answer: By defining a variable that holds a string called “dog”. Now we can get creative with our dog variable. How about if we want to define a phrase that says “I love you”. We can do this with the following code: dog = “I love you” .

This is just scratching the surface of how variables work, but hopefully it’s enough to get you started. 

If you want to learn more about variables and loops, visit the official JavaScript/ECMA-262 5th edition Reference Manual by David Flanagan. It’s an authoritative source for JavaScript coding. He has also written several books on JavaScript which are also worth reading (and worth buying).

If you want to learn more about the use of variables in programming, check out this tutorial .

Functions!

You’ve probably heard of functions before in math class. For example, you might have studied the sine or cosine function. Whenever you study Math, you’re basically doing functions with different variables. Functions are just a series of steps that are carried out in order to produce an answer or result that’s commonly known as a return value . In math you might have a function that tells you how to calculate sine or cosine. In programming, we can also have functions that tell us how to do things such as display a website’s logo, display the current date and time, etc. In JavaScript, functions are very useful as they can be reused throughout your script for multiple purposes.

Create a function in JavaScript

To create a function in JavaScript, simply format the following line of code: function myFunctionName(){ // Put all your code here } . Now what’s this myFunctionName thing? It’s just a label that you give your function so that it is easier for you and other people using your script to identify what the function does. If you feel like you need more than one function, just create more labels under myFunctionName .

 

LEAVE A REPLY

Please enter your comment!
Please enter your name here