MCS-170 The Nature of Computer Science

Chapter 4


1. Dynamic Web Pages Using JavaScript

2. Dynamic vs Static Pages

3. Programming Language

4. Using JavaScript

<html>
    <head>
       <title> My First JavaScript Page </title>
    </head>

                       <body>
                           <h1>  Here is some JavaScript-generated text: </h1>
                           <script type="text/javascript">
                               document.write("<i> Message generated on-the-fly</i> ");
                           </script>
                       </body>
                     </html>

5. Our First JavaScript Statement (instruction)

6. Variables

variables

<script type="text/javascript">
    var name;                                     // Declaration
    name = "bugs";                            // Initialization
    document.write("<i> Hello " + name + " </i> ");   // Reference
</script>

7. Prompts for User Input

<script type="text/javascript">
       name = prompt("Please enter your name", "name goes here");
       document.write("Hello " + name + ", how are you?");
       feeling = prompt("Please enter how you are feeling", "");
       document.write("<p>Try smiling while you are " + feeling +".</p>");
    </script>
Here's how it works on a page -- simpleProg.html