Javascript - Functions

<script type = "text/javascript">
   <!--
      function functionname(parameter-list) {
         statements
      }
   //-->
</script>

<script type = "text/javascript">
   <!--
      function sayHello() {
         alert("Hello there");
      }
   //-->
</script>

<html>
   <head> 
      <script type = "text/javascript">
         function sayHello() {
            document.write ("Hello there!");
         }
      </script>
     
   </head>
 
   <body>
      <p>Click the following button to call the function</p>     
      <form>
         <input type = "button" onclick = "sayHello()" value = "Say Hello">
      </form>     
      <p>Use different text in write method and then try...</p>
   </body>
</html>

<html>
   <head> 
      <script type = "text/javascript">
         function sayHello(name, age) {
            document.write (name + " is " + age + " years old.");
         }
      </script>     
   </head>
 
   <body>
      <p>Click the following button to call the function</p>     
      <form>
         <input type = "button" onclick = "sayHello('Zara', 7)" value = "Say Hello">
      </form>     
      <p>Use different parameters inside the function and then try...</p>
   </body>
</html>

<html>
   <head> 
      <script type = "text/javascript">
         function concatenate(first, last) {
            var full;
            full = first + last;
            return full;
         }
         function secondFunction() {
            var result;
            result = concatenate('Zara', 'Ali');
            document.write (result );
         }
      </script>     
   </head>
 
   <body>
      <p>Click the following button to call the function</p>     
      <form>
         <input type = "button" onclick = "secondFunction()" value = "Call Function">
      </form>     
      <p>Use different parameters inside the function and then try...</p> 
  </body>
</html>

No comments:

Post a Comment

Welcome

Lets learn java script