මචන්ලා මට මේක කවුරු හරි කරල දෙන්න කරුණාකරල



ලොකු උදව්වකි
(More Javascripting)
Program 1:
Read the user's name from the prompt box as a string. Use that name to print, "Hi, <name>"
Program 2:
Prompt the user for 2 numbers (say, x and y). Compare the two numbers. If x is greater than y, print "x is greater than y". If y is greater than x, print "y is greater than x". (make sure you print the actual numbers entered by the user)
Program 3:
Get today's date using the Date class. Print the date, month, and year. If the day is a weekday, print "uh..oh...it is a weekday". If the day is either Saturday or Sunday, print "Great...It is the weekend".
Use the following methods:
getFullYear ( ) - Retrieves the year component of the date as a 4-digit number.
getMonth ( ) - Retrieves the month component of the date as a number from 0 to 11 (0=January, 1=February, etc)
getDate ( ) - Retrieves the day-of-month component of the date as a number from 1 to 31
getDay ( ) - Retrieves the day of the week component of the date as a number from 0 to 6 (0=Sunday, 1=Monday, etc)
Sample code:
The following code prints today's date and month.
<html>
<head>
<title>Write the Date</title>
<script language="JavaScript">
<!-- hide me
// get the date information
//
var today = new Date();
var the_day = today.getDate();
var the_month = today.getMonth();
// correct for the month starting from zero
//
the_month = the_month + 1;
// create the string you want to print
//
var the_whole_date = the_month + "/" + the_day;
// show me -->
</script>
</head>
<body>
Today's date is:
<script language="JavaScript">
<!-- hide me
// write the date
//
document.write(the_whole_date);
// show me -->
</script>
</body>
</html>
Program 4:
[FONT="]<![/FONT][FONT="]DOCTYPE[/FONT][FONT="] html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">[/FONT]
[FONT="]<[/FONT][FONT="]html[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]head[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]meta[/FONT][FONT="] http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">[/FONT]
[FONT="]<[/FONT][FONT="]title[/FONT][FONT="]>[/FONT][FONT="]Insert title here[/FONT][FONT="]</[/FONT][FONT="]title[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]</[/FONT][FONT="]head[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]body[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]script[/FONT][FONT="] type="text/javascript">[/FONT]
[FONT="] [/FONT]
[FONT="]if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);[/FONT]
[FONT="] var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number[/FONT]
[FONT="] if (ffversion>=3)[/FONT]
[FONT="] document.write("You're using FF 3.x or above")[/FONT]
[FONT="] else if (ffversion>=2)[/FONT]
[FONT="] document.write("You're using FF 2.x")[/FONT]
[FONT="] else if (ffversion>=1)[/FONT]
[FONT="] document.write("You're using FF 1.x")[/FONT]
[FONT="]}[/FONT]
[FONT="]else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;[/FONT]
[FONT="] var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number[/FONT]
[FONT="] if (ieversion>=8)[/FONT]
[FONT="] document.write("You're using IE8 or above")[/FONT]
[FONT="] else if (ieversion>=7)[/FONT]
[FONT="] document.write("You're using IE7.x")[/FONT]
[FONT="] else if (ieversion>=6)[/FONT]
[FONT="] document.write("You're using IE6.x")[/FONT]
[FONT="] else if (ieversion>=5)[/FONT]
[FONT="] document.write("You're using IE5.x")[/FONT]
[FONT="]}[/FONT]
[FONT="]else[/FONT]
[FONT="] document.write("n/a")[/FONT]
[FONT="] document.write("n/a")[/FONT]
[FONT="] [/FONT]
[FONT="]</[/FONT][FONT="]script[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="] [/FONT]
[FONT="]</[/FONT][FONT="]body[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]</[/FONT][FONT="]html[/FONT][FONT="]>[/FONT]




ලොකු උදව්වකි

(More Javascripting)
Program 1:
Read the user's name from the prompt box as a string. Use that name to print, "Hi, <name>"
Prompt the user for 2 numbers (say, x and y). Compare the two numbers. If x is greater than y, print "x is greater than y". If y is greater than x, print "y is greater than x". (make sure you print the actual numbers entered by the user)
Get today's date using the Date class. Print the date, month, and year. If the day is a weekday, print "uh..oh...it is a weekday". If the day is either Saturday or Sunday, print "Great...It is the weekend".
Use the following methods:
getFullYear ( ) - Retrieves the year component of the date as a 4-digit number.
getMonth ( ) - Retrieves the month component of the date as a number from 0 to 11 (0=January, 1=February, etc)
getDate ( ) - Retrieves the day-of-month component of the date as a number from 1 to 31
getDay ( ) - Retrieves the day of the week component of the date as a number from 0 to 6 (0=Sunday, 1=Monday, etc)
Sample code:
The following code prints today's date and month.
<html>
<head>
<title>Write the Date</title>
<script language="JavaScript">
<!-- hide me
// get the date information
//
var today = new Date();
var the_day = today.getDate();
var the_month = today.getMonth();
// correct for the month starting from zero
//
the_month = the_month + 1;
// create the string you want to print
//
var the_whole_date = the_month + "/" + the_day;
// show me -->
</script>
</head>
<body>
Today's date is:
<script language="JavaScript">
<!-- hide me
// write the date
//
document.write(the_whole_date);
// show me -->
</script>
</body>
</html>
[FONT="]<![/FONT][FONT="]DOCTYPE[/FONT][FONT="] html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">[/FONT]
[FONT="]<[/FONT][FONT="]html[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]head[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]meta[/FONT][FONT="] http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">[/FONT]
[FONT="]<[/FONT][FONT="]title[/FONT][FONT="]>[/FONT][FONT="]Insert title here[/FONT][FONT="]</[/FONT][FONT="]title[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]</[/FONT][FONT="]head[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]body[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]<[/FONT][FONT="]script[/FONT][FONT="] type="text/javascript">[/FONT]
[FONT="] [/FONT]
[FONT="]if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);[/FONT]
[FONT="] var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number[/FONT]
[FONT="] if (ffversion>=3)[/FONT]
[FONT="] document.write("You're using FF 3.x or above")[/FONT]
[FONT="] else if (ffversion>=2)[/FONT]
[FONT="] document.write("You're using FF 2.x")[/FONT]
[FONT="] else if (ffversion>=1)[/FONT]
[FONT="] document.write("You're using FF 1.x")[/FONT]
[FONT="]}[/FONT]
[FONT="]else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;[/FONT]
[FONT="] var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number[/FONT]
[FONT="] if (ieversion>=8)[/FONT]
[FONT="] document.write("You're using IE8 or above")[/FONT]
[FONT="] else if (ieversion>=7)[/FONT]
[FONT="] document.write("You're using IE7.x")[/FONT]
[FONT="] else if (ieversion>=6)[/FONT]
[FONT="] document.write("You're using IE6.x")[/FONT]
[FONT="] else if (ieversion>=5)[/FONT]
[FONT="] document.write("You're using IE5.x")[/FONT]
[FONT="]}[/FONT]
[FONT="]else[/FONT]
[FONT="] document.write("n/a")[/FONT]
[FONT="] document.write("n/a")[/FONT]
[FONT="] [/FONT]
[FONT="]</[/FONT][FONT="]script[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="] [/FONT]
[FONT="]</[/FONT][FONT="]body[/FONT][FONT="]>[/FONT][FONT="][/FONT]
[FONT="]</[/FONT][FONT="]html[/FONT][FONT="]>[/FONT]