JAVASCRIPT HELP please

Nov 14, 2012
22
2
0
මචන්ලා මට මේක කවුරු හරි කරල දෙන්න කරුණාකරල:(:(:(:(
ලොකු උදව්වකි
:(
(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=&quot]<![/FONT][FONT=&quot]DOCTYPE[/FONT][FONT=&quot] html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">[/FONT]
[FONT=&quot]<[/FONT][FONT=&quot]html[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot]<[/FONT][FONT=&quot]head[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot]<[/FONT][FONT=&quot]meta[/FONT][FONT=&quot] http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">[/FONT]
[FONT=&quot]<[/FONT][FONT=&quot]title[/FONT][FONT=&quot]>[/FONT][FONT=&quot]Insert title here[/FONT][FONT=&quot]</[/FONT][FONT=&quot]title[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot]</[/FONT][FONT=&quot]head[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot]<[/FONT][FONT=&quot]body[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot]<[/FONT][FONT=&quot]script[/FONT][FONT=&quot] type="text/javascript">[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent)){ //test for Firefox/x.x or Firefox x.x (ignoring remaining digits);[/FONT]
[FONT=&quot] var ffversion=new Number(RegExp.$1) // capture x.x portion and store as a number[/FONT]
[FONT=&quot] if (ffversion>=3)[/FONT]
[FONT=&quot] document.write("You're using FF 3.x or above")[/FONT]
[FONT=&quot] else if (ffversion>=2)[/FONT]
[FONT=&quot] document.write("You're using FF 2.x")[/FONT]
[FONT=&quot] else if (ffversion>=1)[/FONT]
[FONT=&quot] document.write("You're using FF 1.x")[/FONT]
[FONT=&quot]}[/FONT]
[FONT=&quot]else if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;[/FONT]
[FONT=&quot] var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number[/FONT]
[FONT=&quot] if (ieversion>=8)[/FONT]
[FONT=&quot] document.write("You're using IE8 or above")[/FONT]
[FONT=&quot] else if (ieversion>=7)[/FONT]
[FONT=&quot] document.write("You're using IE7.x")[/FONT]
[FONT=&quot] else if (ieversion>=6)[/FONT]
[FONT=&quot] document.write("You're using IE6.x")[/FONT]
[FONT=&quot] else if (ieversion>=5)[/FONT]
[FONT=&quot] document.write("You're using IE5.x")[/FONT]
[FONT=&quot]}[/FONT]
[FONT=&quot]else[/FONT]
[FONT=&quot] document.write("n/a")[/FONT]
[FONT=&quot] document.write("n/a")[/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]</[/FONT][FONT=&quot]script[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot] [/FONT]
[FONT=&quot]</[/FONT][FONT=&quot]body[/FONT][FONT=&quot]>[/FONT][FONT=&quot][/FONT]
[FONT=&quot]</[/FONT][FONT=&quot]html[/FONT][FONT=&quot]>[/FONT]
 
Jul 10, 2011
5,011
473
0
smiley-02.gif
smiley-02.gif
smiley-02.gif
smiley-02.gif
smiley-02.gif
smiley-02.gif
smiley-02.gif
 

nismok

Well-known member
  • Jun 27, 2008
    9,391
    673
    113
    Program 1 -

    var name=prompt("Please enter your name","Windows 8");
    if (name!=null && name!="")
    {
    x="Hi, " + name;
    document.write(x);
    }
     
    Last edited:

    rajith123

    Well-known member
  • May 4, 2007
    1,625
    173
    63
    වින්ඩොස් 8;13852990 said:
    please help kauruth naddoooooooooooo?

    දැන් මොකද්ද වෙන්න ඕනා. පැහැදිලිව කිව්වොත් උදව්වක් කරන්න පුළුවන්
     

    nismok

    Well-known member
  • Jun 27, 2008
    9,391
    673
    113
    Program 2 -

    var x=prompt("Enter x","");
    var y=prompt("Enter y","");

    if ( x > y ){
    document.write(x + " is greater than " + y);
    }
    else{
    document.write(y + " is greater than " + x);
    }