JSFiddle - React, Tailwind, and code Playground

by Ruchi Samdariya

HTML

<SCRIPT>
function sumDigits(num) {
     var i, sum = 0;                 

     for (i = 1; i <= num; i++) {
             sum += i;              
     }

     
     alert("The sum of the digits from 1 to "+ num + " is:\n\n\t " + sum);
}

</SCRIPT>

<BODY>

Looping Functions - Calculate the sum of the digits.

<FORM NAME="SumNums">
     The sum of the digits from 1 to:
     <INPUT TYPE="text" NAME="charNum">
     <INPUT TYPE="button" VALUE="Calculate"
       onClick="sumDigits(SumNums.charNum.value)">
</FORM>