Functions
/*
a function is reusable piece of code.
function is the keyword
function can be defined once, and used many time
*/
//function defincation
function add(a, b)
{
c = a + b
return c
}
//function call
document.write(add(2, 5))
document.write("<BR>")
document.write(add(20, 50))
//alert is javascript builtin function for displaying messages
function showme()
{
alert("Hello! I am an alert")
}
function printme()
{
print()
}
function confirmation()
{
var answer = confirm("Are you sure you want to leave this page")
if(answer)
{
alert("Bye Bye")
close()
}
else
{
alert("Thanks for sticking around")
}
}
<script type="text/javascript">
/*
a function is reusable piece of code.
function is the keyword
function can be defined once, and used many time
*/
//function defincation
function add(a, b)
{
c = a + b
return c
}
//function call
document.write(add(2, 5))
document.write("<BR>")
document.write(add(20, 50))
//alert is javascript builtin function for displaying messages
function showme()
{
alert("Hello! I am an alert")
}
function printme()
{
print()
}
function confirmation()
{
var answer = confirm("Are you sure you want to leave this page")
if(answer)
{
alert("Bye Bye")
close()
}
else
{
alert("Thanks for sticking around")
}
}
</script>
Going to next page
function newpage()
{
window.location = "http://www.google.com"
}
<script type="text/javascript">
function newpage()
{
window.location = "http://www.google.com"
}
</script>