Tom Kelliher, CS 102
Feb. 19, 1999
Internet Timeline.
Structural elements of JavaScript, I/O.
The process of transforming the description of a problem into the solution of that problem by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies, techniques, and tools.
A few problem examples:
Details to be determined:
Algorithm:
A sequence of a finite number of steps arranged in a specific logical order which, when executed, produces the solution for a problem.
An algorithm must satisfy the following requirements:
Pseudocode:
A semiformal, English-like language with a limited vocabulary that can be used to design and describe algorithms.
C. Bohm and G. Jacopini proved in 1966 than pseudocode required only three structural elements
A series of steps or statements that are executed in the order they are written in an algorithm.
Example:
name = prompt("What is your name?", ""); document.write("Hello " + name + "!<br><br>"); age = prompt(name + ", how old are you?", ""); birthYear = currentYear - age - 1;
Statements terminate with a ;.
{
/}
pair grouping for constructing a compound
statement:
{ amountDue = overDue + currentBilling + penalty; document.write("You owe: " + amountDue); }
The alternatives of two courses of action only one of which is taken depending on the outcome of a condition, which is either true or false.
if (condition) then_statement; else else_statement;
Structure of then_part
, else_part
:
{
/}
.
if (payment is overdue) { amountDue = pastDue + currentBilling + penalty; document.write("You owe: " + amountDue); } else document.write("You owe: " + currentBilling);
Alternative nested if-else structure element: else_if
if (grade < 60) document.write("F"); else if (grade < 70) document.write("D"); else if (grade < 80) document.write("C"); else if (grade < 90) document.write("B"); else document.write("A");
Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied.
while (condition) loop_statement;
sum = 0; while (there are input numbers to sum) { number = prompt("Next number: ", ""); sum = sum + number; } document.write("The sum is: " + sum);