Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Javascript Programming


  • Please log in to reply
4 replies to this topic

#1 N2TheRed

N2TheRed

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:01:43 AM

Posted 14 November 2005 - 12:18 PM

I was wanting help understanding what part is a statement and what part is the Expression:

Example: 1

function checker() {
var user_name="Billy Moore"
var user_password="billy moore"

var entered_user_name=prompt("Please Enter User Name: ", " ");
var entered_user_password=prompt("Please Enter User Password: " , " ");

if ((entered_user_name == user_name) && (entered_user_password ==
user_password))
{
document.write("Your Officially Logged In!");
}
else
{
document.write("Your User Name and /or password is incorrect");
}
}


.......................................................
I was wondering what parts are the Expression and Statements.
......................................................

If you have anyother examples to my question that are better examples Please Do reply.

What i'm looking for is a diagram of what is what.


Thanks

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:12:43 AM

Posted 14 November 2005 - 04:12 PM

An instruction written in a high-level language. A statement directs the computer to perform a specified action. A single statement in a high-level language can represent several machine-language instructions. Programs consist of statements and expressions. An expression is a group of symbols that represent a value.


http://www.webopedia.com/TERM/s/statement.html

Can you figure it out from there? This sounds like a homework assignment, and I wouldn't want to give away too much. ;)

EDIT: Just an FYI, the definitions hold no matter which language you happen to be learning.

#3 N2TheRed

N2TheRed
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:01:43 AM

Posted 14 November 2005 - 07:42 PM

About Expressions:

Expressions Evaluate at RunTime inwhich Literals and /or Variables
can be used.
Literal's are the Actual Unit of Data and the Values stored In the Variables.
Data Types include:

Null....................Has No value
Integer...............decimal, Hexadecimal, and Octal
Floating Point......Decimal Integer, Exponet
Boolean.............Logical True Of False, 1 - 0, Yes or No
String................Collection of Characters inside Qoutes
Arrays...............Is an Indexed List of Similar Items: var fav_cities=["Lufkin", "Longview", "Tyler"]
Lufkin, Longview, and Tyler are the Arrays
Objects.............It's the Named List of Disimilar Items:

1. It always returns a value.
2. 4 Types Of Expressions :
*Arithmetic Expressions
*Comparison Expressions
*String Expressions
*Logical Expressions

Arithmetics Expressions:
The Literal used here is an Integer.
var sum=1 + 2
2 + 2
The expression is "1 + 2". The format is var sum=(operand, Operator, operand), and the "="
sign is the assignment operator that will store the result to the variable "sum".

Operand is the Actual Data in this case it would be "2" and "2"

Comparison Expressions With If/Else:
The data type "Literal" used is called "Boolean" meaning True or false, yes or no , and ect.


if ((entered_user_name == user_name) && (entered_user_password == user_password))

the Expression is in side the ( )'s. It's also a Logical Expression because it is compareing more then
one expression. The Logical Operator is "&&" which means "AND"

"==" is the Comparison Operator for that expression.
It's saying that If (entered_user_name "Equals" user_name) AND (entered_user_password "Equals" user_password)

take this path ELSE take another path.




String Expressions:
The Literal Used here is a String

String Expressions are collection of Characters that goes inside Qoutes.

var user_name="N2TheRed"
there for "=" will return "N2TheRed" which is the value to the Variable "user_name".
So the String Expression is "N2TheRed" in (var user_name="N2TheRed")

So what about
var number1="2"
var number2="2"
......well since it's in qoutes they are no longer Integers they are Just Characters.

say if you did this
var number1="2"
var number2="2"
document.write(number1 + number2);

the result that will be displayed would be "22" and not "4"
what has happend is that the "+" operator now functions as "CONCATENATION" which is a string operator
to join to strings together. So what we did as took the variable "number1" and it's string "2"
and added it with variable number2 and it's string "2"

There for since "+" is the Concatenation operator for String Expressions all we did was just Join

the character 2 and 2 together to make 22.

However if you wanted to achieve the sum of 2 and 2 you have to tell the Computer to take the "Strings" 2 and 2 and returns the Appropriate Number Corrisponding to that string.

So we don't have Integers but we need to convert the String Value of (number1 and number2) to an
integer.

how we do that is by using "parseInt and parseFloat"

parseInt is any whole number
paseFloat is any number that contains a decimal

There for we would have to say instead of

var number1="2"
var number2="2"

document.write(number1 + number2);

it would actually be

var number1="2"
var number2="2"

document.write(parseInt(number1) + parseInter(number2);

That's What I know so far about What Expressions are. I actually had to
reread and think about what it was trying to show me.

If I missed anything or got something wrong Please Let me know so I don't learn it the
a wrong way.

Thanks

#4 N2TheRed

N2TheRed
  • Topic Starter

  • Members
  • 4 posts
  • OFFLINE
  •  
  • Local time:01:43 AM

Posted 14 November 2005 - 07:50 PM

Actually I knew that it was for all programming languages, however i thought it would be best
if I just said Which one I was working on just incase.

But thanks. I actually think that I do have Expressions and statements down as far as how they function
and operate.

#5 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:12:43 AM

Posted 15 November 2005 - 10:28 AM

Boolean is returned as either true or false, nothing else. How that true or false is interpreted is another matter entirely. A false could be a yes, a true could be a no...

Your description of an array declarations seems goofy... it looks to me like you are creating an array called fav_cities, and putting some strings into it.

1. It always returns a value.

What always returns a value? What is a void return type?

You also need to look at your data types.. there are really only 2 different data types. What you are showing are subdivisions. It is important to understand the distinction. I'll give you a hint. One type starts with a 'p'.

What data type is an array?



You are getting a basic grasp of things, providing that you didn't just cut and paste from somewhere. :thumbsup:




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users