Beginning Javascript [Part 1] - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Beginning Javascript [Part 1] (/showthread.php?tid=66836)
Beginning Javascript [Part 1] by vikke on 10-01-2006 at 06:53 AM
Hello,
I decided to make a javascript tutorial which shows the programming basics and some javascript basics. Sorry about my quite bad english, I hope you understand mostly stuff, if you don't, write a reply.
Comments:
Comments simply comment to the code . A comment is like this:
code: // HELLO I'M HERE
The program will not execute that part. I'm using comments to help you out in a code. You don't have to remove them to make your script work.
Variables
Variables could be many different types, here's some of them (AFAIK):
string: this is an array of characters, so it could be "Hello dear mama!!!111" or "õ! [=", or anything. When declaring strings do like this:
code: // Creates a string called MyString, and sets it's value to "Hello World"
var MyString = "Hello World";
integer: a integer is a number, without decimals, some values could be 1, 5, 1000, 3245. When declaring integers do like this:
code: // Creates a integer called MyInteger and sets it's value to 5
var MyInteger = 5;
floats: floats are numbers with decimals. Declare a float like this:
code: // Creates a float with the value 5.31
var MyFloat = 5.31;
boolean: booleans are true or false, when declaring do:
code: // Declares 2 booleans and gives them values.
var MyBoolean = true;
var MyBoolean2 = false;
That's variables, hope you now got a clue about it.
Why variables?
It's simply to storage stuff. For example, if you'd like to spam your contact you could do:
code: SendMessageToContact("Hello!");
SendMessageToContact("Hello!");
SendMessageToContact("Hello!");
SendMessageToContact("Hello!");
But it's much easier to read if you did:
code: var Message = "Hello!";
SendMessageToContact(Message);
SendMessageToContact(Message);
SendMessageToContact(Message);
SendMessageToContact(Message);
Note: That code doesn't work.
Math:
Now, lets include some math
'The most common math-operators are + (plus) - (minus) / (divide) * (times) = (set) += (add to current value) != (not is). Here's some code snippets to use those.
Integers: code: var myInt = 1+1; // myInt is now 2
var anotherInt = myInt * 2; // anotherInt is now 4
myInt += anotherInt; // myInt is now myInt + anotherInt, and that's 4+2=6
Strings:code: var MyString = "I love scripting";
var anotherString = MyString + " Javascript"; // anotherString is now "I love scripting Javascript"
-, *, /, doesn't work while it's a string.
Floats: Same as integers.
Booleans:code: var myBoolean = true;
var anotherBoolean != myBoolean; // anotherBoolean is now false.
Statments:
if-statement: a if-statment checks if a expression is true or false and then does action. Should be like this: code: var myVar = true; // a boolean
if(myVar == true){
// Do code here which will be executed when myVar is true
}
elseif(myVar == false) {
// Do code here which will be executed when myVar is false
}
else {
// If myVar isn't neither false or true.
}
switch-statement: The switch-statement is like the if-statement but more clear.
code: myInt = 1;
switch(myInt){
case 1:
// do what to do if myInt is 1
case 2:
case 3:
// because case 2 is nothing it will still go to 3, so put here what to do if
//myInt 2 or 3
}
I hope I'll have time to do a second one, which will include Loops, MsgPlus! Scriping usage, Arrays and more!!
Thank you, I hope you enjoyed.
vikke
RE: Beginning Javascript [Part 1] by -dt- on 10-01-2006 at 07:15 AM
for further reading look at..
variables : http://developer.mozilla.org/en/docs/Core_JavaScr....5_Guide:Variables
Operators: http://developer.mozilla.org/en/docs/Core_JavaScr..._Guide%3AOperators
conditional statements (If , else , switch...): http://developer.mozilla.org/en/docs/Core_JavaScr...itional_Statements
RE: Beginning Javascript [Part 1] by CookieRevised on 10-01-2006 at 09:24 AM
May I note that JavaScript is not the same as JScript.
Plus! scripting uses JScript, not JavaScript...
Although many things are the same, there are many differences too.
For the purpose and in the context of creating a beginners tutorial it is absolutely important to reference to the proper language and not to a language which is similar to what is used in Plus! scripting.
Official JScript 5.6 reference:
http://msdn.microsoft.com/library/en-us/script56/...6-1bbfe2330aa9.asp
Official JScript 5.6 help file (CHM) (includes vbscript too):
http://www.microsoft.com/downloads/details.aspx?F...-8A76-1C4099D7BBB9
JScript tutorials:
* http://csu.colstate.edu/webdevelop/javascript/jscript/jstutor.htm
http://cobdev.cob.isu.edu/psb/jscript/Jstutor.htm
http://tergestesoft.com/~manuals/jslang/Jstutor.htm
http://www.webf1.com/ScriptDoc/jscript/jstutor.htm
* http://www.dnjonline.com/articles/tutorials/jscript1.html
RE: Beginning Javascript [Part 1] by vikke on 10-01-2006 at 09:33 AM
Ok. I have no idea of what's the diffference.
|