Lowyat.NET Forums

Welcome Guest ( Log In | Register )

LYN wins Intel-Lenovo-Tangs Blogathon challenge. Thank you everybody!
 
RSS feedBump TopicReply to this topicStart new topicStart Poll

Outline · [ Standard ] · Linear+

> Javascript right from the start

mumeichan
post Nov 1 2009, 01:53 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #1


Individual
******

Group: Senior Member
Posts: 1,903
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: May 2005





First of all, I am a a total stranger to web designing. Until 3 days ago I knew nothing about it. I've decided to write my own greasemonkey script and I have done quite a bit of research on the net.

So I got myself a copy of Javascript for Dummies 4th Edition. I expected it to teach me stuff from absolute zero but it seems that it jumps into quite alot of stuff.

I am quite certain I know enough of HTML and CSS that I need to write my GM script. So now what's left is jQuery. I can do simple jQuery stuff but when I see the more advance examples of thing I can't understand them fully.

For example, they use the element "this' and they write " newVar = something" and all those stuff. I need to know what all this things mean. Also I am very confused with when to place brackets and when to start a new line.

The way Javascript for Dummies is written assumes you know all these.

Is there a better book that teaches me one by one what each symbol, word, whatever means and how do I use them and string them together.

Take this for example:
CODE
function calculateTotal(numberOrdered, itemPrice) {
var totalPrice = (numberOrdered * itemPrice) + salesTax
return totalPrice
}


I know at least that function and var are some kind of operators used by javascript, but what dodoes 'calculateTotal' mean? Is that another operator, is that the name of another element somewhere ? Why the the T in total capitalize and not the c in calculate? and what is numberOrdered, itemPrice etc.

I would like a book that tells me what every single word is.

Thanks!

This post has been edited by mumeichan: Nov 1 2009, 01:54 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
toocommon
post Nov 1 2009, 02:11 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #2


Newbie
*

Group: Junior Member
Posts: 49
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Mar 2008




QUOTE(mumeichan @ Nov 1 2009, 01:53 PM)
First of all, I am a a total stranger to web designing. Until 3 days ago I knew nothing about it. I've decided to write my own greasemonkey script and I have done quite a bit of research on the net.

So I got myself a copy of Javascript for Dummies 4th Edition. I expected it to teach me stuff from absolute zero but it seems that it jumps into quite alot of stuff.

I am quite certain I know enough of HTML and CSS that I need to write my GM script. So now what's left is jQuery. I can do simple jQuery stuff but when I see the more advance examples of thing I can't understand them fully.

For example, they use the element "this' and they write " newVar = something" and all those stuff. I need to know what all this things mean. Also I am very confused with when to place brackets and when to start a new line.

The way Javascript for Dummies is written assumes you know all these.

Is there a better book that teaches me one by one what each symbol, word, whatever means and how do I use them and string them together.

Take this for example:
CODE
function calculateTotal(numberOrdered, itemPrice) {
var totalPrice = (numberOrdered * itemPrice) + salesTax
return totalPrice
}


I know at least that function and var are some kind of operators used by javascript, but what dodoes 'calculateTotal' mean? Is that another operator, is that the name of another element somewhere ? Why the the T in total capitalize and not the c in calculate? and what is numberOrdered, itemPrice etc.

I would like a book that tells me what every single word is.

Thanks!
*



i tot calculateTotal is a function? and "calculateTotal" is juz a function name? capital T or not is up to the coder...no specific meaning, juz a naming convention they use...numberOrdered and itemPrice is juz a variable name with the value passed in from outside....for example, when i want to use this function, i would do like , var result = calculateTotal(10, 20); .... shud be like tat rite? =P
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
alanyuppie
post Nov 1 2009, 02:40 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #3


Regular
******

Group: Senior Member
Posts: 1,648
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jul 2006
From: Pekan LEGO, mukim Kepong





yea. naming convention can be anything that suit your eyes, as long as it doesnt clash with reserved words. The book only follows the standard convention that most coders do. First word is lowecased,subsequent word are capitalised.

its easier to read calculateTotal than calculatetotal. the more you code, the more tendency you will create longer function names for easier revision, for eg:

calculateTotalWithoutTax()
refreshMainListWithNewCalculatedTotal()
makeSureUserDoesNotKeyInVulgarWordAndGetsAwayWithIt()

This post has been edited by alanyuppie: Nov 1 2009, 02:41 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
puaka_astro
post Nov 1 2009, 03:52 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #4


Getting Started
**

Group: Junior Member
Posts: 130
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Jun 2007





QUOTE
function calculateTotal(numberOrdered, itemPrice) {
    var totalPrice = (numberOrdered * itemPrice) + salesTax
    return totalPrice
}


1. calculateTotal - function name, name it whatever you wish smile.gif e.g

CODE

function Hello () {}


2. calculateTotal(numberOrdered, itemPrice)
- numberOrdered - variable name, can be anything you like(string please), same as itemPrice
- these vars included in function parameters if you like to pass something e.g i want to do 2 numbers addition, what is 5 + 5 = ?

lets say you have 2 variables A and B

CODE

var A = 5;
var B = 5;


now you want to know what is A + B ? you can do it as var C = A + B or you can code new function just to calculate the addition. e.g \

CODE

function whatever (number1, number2) {
    var result = number1 + number2;
    return result;
}


how do you use the function ? simple, just call the function name and pass 2 vars, you do it like this :

CODE

var C = whatever(A,B);


see the function "whatever", the return means you returning a value, in our example var C = A + B


whatever book you read, turn to page "Function"

thats it.. think simple dude..
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
sunsuron
post Nov 1 2009, 10:29 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #5


PHP Web Developer
*****

Group: Senior Member
Posts: 750
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Nov 2004






That book is the wrong book if you really want to get serious with this stuff. Get this one instead.

user posted image

http://oreilly.com/catalog/9780596000486
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
taitianhin
post Nov 2 2009, 05:54 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #6


Getting Started
**

Group: Junior Member
Posts: 82
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Apr 2005
From: too far to see





naming convention on variable and function name is based on best practise only
ppl use verb, nouns, and sometimes what they do to determine which letter they need to capitalise.
this is to improve the readability of the code.
Happy learning, and hello world thumbup.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post
Azriq007
post Nov 3 2009, 04:02 PM
Show posts by this member only |This post's rating (0+, 0-) | Post #7


Getting Started
**

Group: Junior Member
Posts: 59
Ratings earned: 0+, 0-
Ratings given: 0+, 0-

Joined: Aug 2009





QUOTE(mumeichan @ Nov 1 2009, 01:53 PM)


Take this for example:
CODE
function calculateTotal(numberOrdered, itemPrice) {
var totalPrice = (numberOrdered * itemPrice) + salesTax
return totalPrice
}


I know at least that function and var are some kind of operators used by javascript, but what dodoes [cool.gif'calculateTotal' [B]mean? Is that another operator, is that the name of another element somewhere ? Why the the T in total capitalize and not the c in calculate? and what is numberOrdered, itemPrice etc.

I would like a book that tells me what every single word is.

Thanks!
*



ok... in my experience... although not so much experience using js(JavaScript) that's the right way to declare a function a.k.a method ... where in java technologies best way to declare a method usually somthing like that (calculateTotal)
even a programmer can declare using any name that they like (except for keyword and some term that cannot be applied to declare either variable name, method or class).... if i declare something like this
CODE
function mymethod(){}
it also run without any error.. but usually professional will declare function name like calculateTotal() one....
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Bump TopicReply to this topicTopic OptionsStart new topic
 



----debug section please ignore----
Lo-Fi Version Time is now: 24th November 2009 - 02:56 AM
All Rights Reserved 2003-2009 Vijandren Ramadass (~living on a prayer~)