How-To: Javascript Basics

268 4 1
                                        

                                                                                How-To: Javascript

                                                                                Chapter 1: The Beginning

        For starters, I recommend using http://jsbin.com/ for this computer programming tutorial. As it will increase your knowledge if you practice it, don't worry, I have used that same site for many game makings or small projects. For now, we will just be focusing on the javascript portion. Therefore, you should close the HTML tab, CSS tab, and OUTPUT tab (Simply click the buttons). Leave open the Javascript tab, and open the console tab (To open, again just click). You do NOT need to make an account, but its best if you do so you can save your projects.

        Look to the right at the media to see what it should look like. The picture may be distorted.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

        It sounds cool to make your own games, and it definitely is. It is also lots of fun (At least I think so!). Let's start with your name. Put it in quotation marks ( " " ) surrounding your name, as so -->

"The_Great_One2";

        Did you see that semicolon ( ; )? That is used to tell the program that that piece of code is done, and it can go on. Most interpreters auto read lines without use of semicolons, but it is best to so you won't have to worry about possible future bugs.

        The next three things to go into are: alert, confirm, and prompt. Alert tells the website to send the user some information, it can be useful for bug testing or a small game. Alerts have parantheses ( () ) and inside them contain a boolean, string, object, or number (Don't worry about boolean's or objects for now).

alert("Bug here.");

        Confirm tells the website to ask the user some information, true or false (Yes or no). It can later be used for storing information. Confirms have parantheses ( () ) and inside them contain a boolean, string, object, or number (Don't worry about boolean's or objects for now). And then return a boolean (true or false).

confirm("Is this project good?");

        Prompt tells the website to ask the user some information, any information. It can later be used for storing information. Prompts have parantheses ( () ) and inside them contain a boolean, string, object or number (Don't worry about boolean's or objects for now). And then return the value that the user enters in.

prompt("Enter your favorite fruit");

All of these can be pretty fascinating, but there is more, much more. Such as, var (variables). Variables store information temporarily until run time is over (Plain javascript), or until the site is reloaded (DOM manipulation, used for multiple languages). Variables can store booleans, strings, or numbers.

Strings --> "The_Great_One2"

Numbers --> 1 2 3 4 5 6 7 8 9 0

Booleans --> True, false

Variables start with var, next comes a name for the variable (Can start with lower case, upper case, or underscores), then a for assigning the variable. You then assign it a string, number, or boolean, or an object (Such as arrays, alerts, confirms, and prompts).

var test = prompt("Type anything!");

Variables are espiecally useful for if/else statements. if statements take a parameter of a true equation. If whatever is inside of it is true, it will run whatever is inside of it's brackets ( {} ). Otherwise, it will skip it or go one with other else or else if statements. Some conditionals --> === exactly equal to, in every way. !== not equal to. > more than. >= more than or equal to.less than. <= less than or equal to. There are a few more, but those are all that are needed for now.

var test = true;

if(test) { //The // are called comments, so people can read your code. I did not have any conditionals because no conditionals is understood as test === true

alert(test);

} else if (test === 5) { //Line 2

alert("Not 5 :( ");

 } else {

alert(test); 

}

The else/if conditional (Line 2) can be used as many times as needed.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Want to learn more? Comment down below! Have any specific questions about computer programming (Mainly Javascript, HTML, CSS, or jQuery)? Ask at http://gitter.im/Jadog1/Give_answers. You will need a Github account. You can create one at: http://www.github.com/

How-To: Javascript BasicsWhere stories live. Discover now