Home

Egg Directory / Search

New Eggs / Best of New

New Blogs / Pics / Activity
New Files / Movies
Community Forum

Group Directory

 

 
Edit PageMessage SYLARAdd CommentAdd to FavoritesEmail to Friend

Sylars Basic JavaScript Tutorial pt2

DO NOT TRY THIS AT HOME : Rotteneggs.com text files and message bases are for INFORMATIONAL PURPOSES ONLY. DO NOT undertake any project based upon any information obtained from this or any other web site.We are not responsible for, nor do we assume any liability for, damages resulting from the use of any information on this site.
(80 votes)
Published: Jan 11, 2008 1:00 p.m.
In 3 Favorites Lists
Viewed 253 times


Once again Before you read this egg remember that wherever it says 5cript or js replace with s c r i p t and j a v a s c r i p t respectively.

Here is part 2 of my js egg. This, in my opinion, is the more interesting part as it deals with more things you can see as well as more user interactive features. Using this egg requires knowledge of the most basic js presented in my other here

This egg will cover:
-Alerts
-prompts
-functions
-buttons

Alerts:

Alerts are useful if you want to tell the user of your website something, warn them of something, or flat out annoy them (by using lots and lots of alerts).

This is what an alert looks like:



This is how an alert is created:

<5cript type="text/js">
alert("YOUR TEXT HERE");
</5cript>

Depending on where you place your alert in your html code your alert can pop up at different times

If you place it inside the head tag (shown below) the alert will pop up before the page loads.

<head>

<5cript type="text/js">
alert("Sylar");
</5cript>

</head>



If you place it inside the body tag (shown below) the alert will pop up after the page loads. (As shown by the awesome picture behind the alert)

<body >
<img src=http://www.clubpenguin.com/fun/fan_art/images/01-08-08_03_lg.jpg>
<5cript type="text/js">
alert("Sylar");
</5cript>

</body >



Prompts:

Prompts are a way to obtain information from a user. For things like for loops and if/elses (explained in my previous egg) prompts can serve as a useful tool for receiving values.

Prompts are stored into vars (also explained in my previous egg) and are created like this.

<5cript type="text/js">

var your_var_name=prompt(“what you want above the prompt”);

</5cript>

This is what a prompt looks like:



Say you wanted to ask what a member on RE’s name was and afterwards create an alert saying “Hello (member name)”. You could do this like so:

<5cript type="text/js">

var name=prompt(“What is your name on RE?”);
alert(“Hello ”+name);

</5cript>

This is what that would look like:






Functions:

Functions are multiple pieces of code assigned to one variable that executes all of the pieces of code inside of it when called upon. (If that makes sense.)

Here is the basic structure of a function

<5cript type="text/js">

function your_function_name(optional var)
{
alert(Hello)
}

</5cript>

All you need to do is choose a name and create a body of code for it to execute. Functions are useful because they allow you to reuse code without rewriting it.

Say I create this function:

function say_hello()
{
document.write(“Hello”);
}

Now rather than typing document.write(Hello); to print Hello, I can just place say_hello(); and Hello will be printed like so:

say_hello();
say_hello();
say_hello();

Will result in:



A function that takes a variable can be useful because it can very easily be used with many values:

function multiply_by_five(userNum)
{
var product= userNum*5;
document.write(product);
}

This takes the user inputted variable, multiplies it by 5 and prints the product.

So if multiply_by_five(4) is called 20 will be returned because it takes 4 and multiplies it by 5.

Buttons:

Buttons are a nice component in a website that have the ability to execute a function. This is very convenient because for example, if you want an alert or a prompt to come up when a user chooses, you can set a button to the task.

The basic structure of a button is:

<input type="button" value="What you want the button to say"
 

Add Egg To Watchlist

 


SYLAR

Jan 11, 2008 1:04 pm -
onclick="the function you want the button to execute">

So lets create an example function and button to execute it:

function get_name()
{
var name=prompt(“What is your name”);
document.writ (name);
}



When you click the button



It prompts for your name



Then prints it



If you write any code, show it to me, I’ll give you tips and show you improvements to make your code better.If you are having trouble with anything feel free to pm me at anytime. Like I said in the previous egg, I will (eventually) be adding this to my RE site. I will most likely write another programming language egg in the near future.

Enjoy
-Sylar


SYLA

Jan 11, 2008 1:05 pm -
sorry about the missing half...idk why it did that


myincrediblycreativen me

Jan 11, 2008 1:14 pm -
So when Weasel finally gives up on us, will you be our savior? lol

Make us a new site.


myincrediblycreative ame

Jan 11, 2008 1:16 pm -
This is what it is supposed be. Sorry I hit the wrong punctuation cause I am talking on the phone at the same time as typing.

Quote:
So when Weasel finally gives up on us, will you be our savior? lol

Make us a new site?


By the way 5*

Jan 11, 2008 1:25 pm -
nice 5* + favs man


SYLAR

Jan 11, 2008 1:58 pm -
nope...haven’t learned it...yet

Jan 11, 2008 4:49 pm -
Foive.


Wh0yathink

Jan 11, 2008 5:05 pm -
I agree with "myincrediblycreativ name"

5*

Sweet job


scamartist_16

Jan 11, 2008 5:24 pm - nice
thanx nice egg *5


bullzeye

Jan 11, 2008 6:55 pm -
5* just like your first egg


J-Rock

Jan 11, 2008 7:21 pm -
never in my life am i going to use this, but it’s pretty cool, and well done. 5*


Yipper

Jan 12, 2008 9:31 am -
Whoo Hoo nice egg 5** for you.


Spud-2520

Jan 15, 2008 10:27 am - Thing
I might use this at one point 4 good effort

Home | Contact Us | Sign Up
Visit our companion site, Prankpedia.com
Please read the LEGAL DISCLAIMER & CONTENT GUIDELINES
© 2008 rotteneggs.com - A Social Network for Pranksters.
0.439504 (Server 2)