Friday, 26 July 2013

JavaScript - Basics 1

JavaScript a simple and a really easy to comprehend programming language. It is mainly used in the browser when coding in HTML. If you want to implement JavaScript or start coding JS in HTML; you will have to use these tags: <script> JAVASCRIPT CODE </script>. That is the easiest way to start.

Confirm & Alert

When using a Confirm Command or Alert, a screen pops up with the String you put in it. To use the confirm or the Alert command; You first type the word either confirm or alert then open some parentheses and inside the them open some quotes, and inside those type your message. Remember, all commands end with a semicolon, it's like a period but for programming languages (Basically, you tell the computer when you stop a command, or finish one). 
EXAMPLE FOR ALERT: alert("Your Message");
EXAMPLE FOR CONFIRM: confirm("Your Message");

The difference between a Confirm and an Alert is that, alerts make a pop up box with just the button "Ok", and a Confirm command makes a pop up box where you can choose from "Ok" and "Cancel" (These 2 options give off a different feedback if you implement some more advanced code, but we will get to that later on).

YOU CAN TRY OUT ALL THE CODES, AND TEST THEM BY GOING TO THIS SITE: http://www.writecodeonline.com/js/

var

A var is a keyword you use, when you are declaring a varibale. You always have to use that to make one, if it's an integer(Number), string(Letters), or a boolean(True or False), unlike Java. It may not seem like much, but once you get the hang of coding in JS, you're gonna see yourself using this keyword more than you expected.

prompt

A prompt is like a Confirm or Alert, but it's more of a question than a statement. When using this command properly, it should pop up a screen, like in confirm/alert, where it shows the String you want it to show, but it also shows a text box, where you can type anything you want, and that String that you put in the text box, will become a new variable. To sum it all up, it goes like this; You declare a new variable (EX: var myVariable), then you make it equal to a prompt, (EX: var myVariable = prompt) then after the prompt keyword, you open some parentheses just like in a confirm/alert command and all that other stuff (quotes, and semicolon). Here is an example:
var myPromptVariable = prompt("What is you age?");
Try putting that ^^^ in http://www.writecodeonline.com/js/

That's all for today, tune in for some more coding tutorials/tips or email me at tekbird_rick@outlook.com

-Rick "Rixel" (TekBird)

No comments:

Post a Comment