You are not connected. Please login or register

View previous topic View next topic Go down  Message [Page 1 of 1]

1 {Java4noobs} on Thu Feb 17, 2011 12:19 am

des

avatar
Achiever
Loading
Basic JavaScript code everyone should know.
The = and == and === operators
The = operator assigns a value to something, either a interger or string
Code:
function var() {
var x=0; //Assaigns x to the interger 0
var y="0"; //Assiagns y to the string "0"
//the above 2 are very different, don't be fooled by the same number in both
}
The == operator compare 2 values
Code:
function var() {
  if (x==0) { //Tests if x EQUALS 0
    if (y=="0") { //Tests if y EQUALS 0
    document.write("Both Variable Are Correct");
    }
  }
}
The === operator test if something is the same value and type
Code:
function var() {
  if (x===y) {
  document.write("The variables are wrong!");
  }
}

The other operators: !=, !==, &&, ||, ++, --
!= is used when you want to values NOT to equal each others values
Code:

function var() {
  if (x!=y) { //Tests if x DOESN'T equal y
  document.write("The 2 values don't equal each other's values");
  }
}
&& means and, it can be used to test more then one if condition
Code:

function var() {
  if (x==0 && y=="0") { //Test if x==0 AND y=="0"
  document.write("The Variables are correct");
  }
}
|| means or, it is used if 2 things can trigger an event
Code:

function var() {
  if (x==0 || y=="0") { //Tests wether x==0 OR y=="0"
  document.write("At Least one variable is correct");
  }
}
++ means increment or +1
Code:

function var() {
x++; //x+1
}
-- means decrement or -1
Code:
function var() {
x--; //x-1
}


The loops, While and For
The While loop keeps executing until a condition is false
Code:
while (x<10) {
x++;
}
The For loop repeats a certain amount of times
Code:
for (x==0;x<10;x++;) {
document.write("x equals " + x);
}
Changing a text value with something other than document.write
Code:

<html>
<body>
<script type="text/javascript">
function change() {
document.getElementById("p").innerHTML="Hello"; //This gets the elements name then innerHTML changes it
}
</script>

<p id="p" onclick="change()">Click me to change the message</p>
</body>
</html>
Changing a style sheet
Although I have never seen it used before this is a code snippet I found in a book
Code:

<html>
<head>

<style id="normal">
background-color:#B0E0E6;
</style>

<style id="green">
background-color:#008000;
</style>

</head>
<body>

<input type="button" onclick="setStyle('green')" value="Green Background">

</body>
</html>
Wow that was alot to type, feel free to ask questions and I will answer them ASAP


2 Re: {Java4noobs} on Thu Feb 17, 2011 12:24 am

The Professor

avatar
Contributor
Loading
You might wanna specify that the language you're using is JavaScript and not Java.

3 Re: {Java4noobs} on Thu Feb 17, 2011 12:25 am

des

avatar
Achiever
Loading
Protozoid wrote:You might wanna specify that the language you're using is JavaScript and not Java.
Desu wrote:Basic JavaScript code everyone should know.
Once they read that, they'll know what I mean.

4 Re: {Java4noobs} on Thu Feb 17, 2011 12:41 am

The Professor

avatar
Contributor
Loading
True, but the users might feel like they were mislead.



Last edited by Protozoid on Mon Feb 21, 2011 7:30 pm; edited 1 time in total

5 Re: {Java4noobs} on Mon Feb 21, 2011 6:32 pm

Nova

avatar
Member
Loading
JavaScript != Java; all your threads named it Java, kid.



Last edited by Nova on Tue Mar 01, 2011 8:02 pm; edited 1 time in total

6 Re: {Java4noobs} on Mon Feb 21, 2011 7:31 pm

The Professor

avatar
Contributor
Loading
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.

Lol, I totally noticed that. Though I figured he'd have the common sense to change the names of them.

Oh well.

7 Re: {Java4noobs} on Mon Feb 21, 2011 8:30 pm

Nova

avatar
Member
Loading
Protozoid wrote:
Nova wrote:JavaScript != Java; all your threads named it Java, kid.

Lol, I totally noticed that. Though I figured he'd have the common sense to change the names of them.

Oh well.
Desu is a kid nothing more, he lacks common sense.



Last edited by Nova on Tue Mar 01, 2011 7:58 pm; edited 1 time in total

8 Re: {Java4noobs} on Tue Mar 01, 2011 12:17 pm

Guest


Guest
Loading
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

9 Re: {Java4noobs} on Tue Mar 01, 2011 7:59 pm

Nova

avatar
Member
Loading
Whores wrote:
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

I made a typo, get over yourself.

PS: It's not like he wrote this guide anyways.

10 Re: {Java4noobs} on Tue Mar 01, 2011 10:40 pm

Guest


Guest
Loading
Nova wrote:
Whores wrote:
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

I made a typo, get over yourself.

PS: It's not like he wrote this guide anyways.
isn't everything practically stolen anyway?

11 Re: {Java4noobs} on Tue Mar 01, 2011 11:28 pm

The Professor

avatar
Contributor
Loading
Whores wrote:
Nova wrote:
Whores wrote:
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

I made a typo, get over yourself.

PS: It's not like he wrote this guide anyways.
isn't everything practically stolen anyway?

Simple answer, no.

12 Re: {Java4noobs} on Wed Mar 02, 2011 12:58 pm

Guest


Guest
Loading
Mhm, does this site have ANY common sense lol?

13 Re: {Java4noobs} on Wed Mar 02, 2011 1:01 pm

Guest


Guest
Loading
Protozoid wrote:
Whores wrote:
Nova wrote:
Whores wrote:
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

I made a typo, get over yourself.

PS: It's not like he wrote this guide anyways.
isn't everything practically stolen anyway?

Simple answer, no.
Ahem, proto, really now? I disagree. Like 99.9 % of this forum abuses copy right laws.

14 Re: {Java4noobs} on Wed Mar 02, 2011 9:10 pm

The Professor

avatar
Contributor
Loading
Whores wrote:
Protozoid wrote:
Whores wrote:
Nova wrote:
Whores wrote:
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

I made a typo, get over yourself.

PS: It's not like he wrote this guide anyways.
isn't everything practically stolen anyway?

Simple answer, no.
Ahem, proto, really now? I disagree. Like 100.0 % of this forum abuses copy right laws.

Fixed.

But yeah, next time that you're not referring to everything in general, specify what you meant. In your case, you should of said "isn't everything in this forum practically stolen anyway?".

15 Re: {Java4noobs} on Wed Mar 02, 2011 10:34 pm

Guest


Guest
Loading
Protozoid wrote:
Whores wrote:
Protozoid wrote:
Whores wrote:
Nova wrote:
Whores wrote:
Nova wrote:JavaScript != Java; all you're threads named it Java, kid.
Mhm-hm Derrick, you stated you're as in the person, you're dumb today etc... it should be YOUR threads named it Java as in he owns that thread mkay?

I made a typo, get over yourself.

PS: It's not like he wrote this guide anyways.
isn't everything practically stolen anyway?

Simple answer, no.
Ahem, proto, really now? I disagree. Like 100.0 % of this forum abuses copy right laws.

Fixed.

But yeah, next time that you're not referring to everything in general, specify what you meant. In your case, you should of said "isn't everything in this forum practically stolen anyway?".
Well 99.9 % is almost everything; is everything to be honest, the only thing that isn't HALF bad is the URL link.

16 Re: {Java4noobs} on Sat Apr 02, 2011 4:33 am

The Anonymous

avatar
Top Dog
Loading
What is Programming?

I am new to this can someone inform me about Programming?

Sponsored content


Loading

View previous topic View next topic Back to top  Message [Page 1 of 1]

Related topics

Permissions in this forum:
You cannot reply to topics in this forum