Ex2 Javascript
Ex2 Javascript
Unit-1: Javascript
<html>
<head>
<title>An Addition Program</title>
<script type = "text/javascript">
<!--
var firstNumber;
var secondNumber;
var number1;
var number2;
var sum;
if ( hour >= 6 )
// determine whether it is after 6 PM
document.write( "<h1>Good Evening, " );
} // end if
document.writeln( name +", welcome to JavaScript programming!</h1>" );
// -->
</script></head><body></body></html>
total = 0;
gradeCounter = 1;
gradeCounter = gradeCounter + 1;
}
14. Write a program in javascript to find the sum the Even Integers from 2 to 100
<html>
<head>
<title>Sum the Even Integers from 2 to 100</title>
<script>
var sum = 0;
document.writeln( "The sum of the even integers " + "from 2 to 100 is " + sum );
</script>
</head><body></body></html>
17. Write a program in javascript to display the heading in different levels using do..while
statement
<html>
<head> <title>Using the do...while Repetition Statement</title>
<script>
var counter = 1;
do {
document.writeln( "<h" + counter + ">Level" + counter + " </h" + counter + ">" );
++counter;
} while ( counter <= 6 );
</script>
</head><body></body></html>
function square( y )
{
return y * y;
}
</script>
</head><body></body> </html>
function maximum( x, y, z )
{
return Math.max( x, Math.max( y, z ) );
}
</script>
</head><body></body> </html>
20. Write a program in Javascript to find the factorial using recursion with event handling
<html>
<head>
<title>Recursive Factorial Function</title>
<script>
function calculateFactorials()
{
for ( var i = 0; i <= 10; ++i )
output += "<p>" + i + "! = "+ factorial( i )+"</p>";
<h1>Factorials of 0 to 10</h1>
<div id = "results"></div>
</body>
</html>
21. Write a program in Javascript that simulates 30 rolls of a six-sided die and displays the
value of each roll
<html>
<head>
<title>Shifted and Scaled Random Integers</title>
<script>
var value;
document.writeln( "<p>Random Numbers</p><ol>" );
for ( var i = 1; i <= 30; ++i )
{
value = Math.floor( 1 + Math.random() * 6 );
document.writeln( "<li>" + value + "</li>" );
}
document.writeln( "</ol>" );
</script>
</head><body></body></html>
10 | P a g e H.Bemesha Smitha,AP/IT,
LICET
IT6503-WEB PROGRAMMING
Unit-1: Javascript
String Object:
A string is a series of characters treated as a single unit.
A string may include letters, digits and various special characters, such as +, -, *, /, and $.
var color = "blue";
11 | P a g e H.Bemesha Smitha,AP/IT,
LICET
IT6503-WEB PROGRAMMING
Unit-1: Javascript
Date Object:
It provides methods for date and time manipulations
getDate() getMonth() setMinutes( m, s, ms )
getDay() getTime() setMonth( m, d )
getHours() setDate( val ) setSeconds( s, ms )
getMinutes() setHours( h, m, s, ms ) setTime( ms )
getSeconds() setMilliSeconds( ms ) toString()
The booleanValue specifies whether the Boolean object should contain true or false
var b = new Boolean( booleanValue );
document object:
• JavaScript code to manipulate the current document in the browser.
• The document object has several properties and methods, such as method
document.getElementByID,
Methods:
12 | P a g e H.Bemesha Smitha,AP/IT,
LICET