Programming

Tom Kelliher, CS297

Jan. 24, 1997

Outline:

  1. Collect papers.

  2. Quiz.

  3. Return papers.

  4. Programming in a nutshell.

  5. JavaScript hands-on.

Programming in a Nutshell

  1. A very primitive language, English-like but adapted for the computer.

  2. High-level-language compiled to assembly language which is assembled to machine language.

  3. A sequence of simple instructions (statements):
    1. Calculate this and store the result here.

    2. Compare these two values.

  4. Basic constructs:
    1. Straight-line execution.

    2. Conditional execution.

    3. Repetitive execution.

    4. Communicating with the world --- input/output statements.

A Few Comments on the Exercise's Program

<html>
<head>
</head>
<body>
<script><!--
// This is a comment.  You don't need to type-in any of these, except
// for the one at the end.

// Variable declarations.
var name;
var age;
var i;
var currentYear = 1997;
var birthYear;
var response;

// Some straight-line execution.
name = prompt("What is your name?", "");
document.write("Hello " + name + "!<br><br>");

age = prompt(name + ", how old are you?", "");

// A conditional.
if (age >= 30)
   document.write("We can't trust you!<br><br>");
else
   document.write("I wish I were young again!<br><br>");

birthYear = currentYear - age - 1;

response = prompt("Were your born in " + birthYear + "? (y or n)", "");
if (response == "y")
   document.write("I'm smart, aren't I?<br><br>");
else
   document.write("You were born too early in the year!<br><br>");

// A loop.
for (i = 1; i <= age; i = i + 1)
    document.write(i + "<br>");

document.write("<br>Goodbye " + name + "!<br>");

// You need the following comment in your program.
//-->
</script>
</body>
</html>



Thomas P. Kelliher
Fri Jan 24 09:00:40 EST 1997
Tom Kelliher