| <SCRIPT>
var num1, num2; //
global variables
function promptIt() {//
prompt requires a message string and optional default value
num1 = parseInt(prompt("Enter
the first number:", 1));
num2 = parseInt(prompt("Enter
second number:", 10));
}
function calcIt() {
var i, sum = 0;
for (i = num1; i <= num2; i++) sum += i;
// num1 + (num1 + 1) + ... + num2
// Display
result
alert("The
sum of digits from: "+ num1 + " to " + num2 + "
is:\n\n\t " + sum)
}
</SCRIPT>
<FORM>
Click the button to calculate the sum of the
digits:
<INPUT
TYPE="button"
VALUE="Calculate"
onClick="promptIt();
calcIt();">
</FORM> |