Looking to create a function that calculates the sum of an array based on two input values. The first input value is added incrementally until it reaches the second input value. For example, if the lowerLimit is '2' and the upperLimit is '5', the total sum would be 2 + (2+1) + (2+2) + (2+3) + (2+4) + (2+5) = 27. I've attempted to use a variable 'i' that increments from the lowerLimit until it reaches (upperLimit - lowerLimit), but I'm unsure about how to properly write the sum array function. Any guidance would be much appreciated.
Q7 Display
Q7
<!-- Question 7 Start -->
<div role="tabpanel" class="tab-pane tab-pane active" id="q6">
<div class="row">
<div class="col-md-12">
<pre>
Question 7 code:
</pre>
</div>
<div class="col-md-12">
<!-- button -->
<button id="button" class="btn btn-default" type="button">Question Seven Solution</button>
</div>
<div class="col-md-12">
<!-- result -->
<div id="result"></div>
</div>
</div>
</div>
<script>
$(document).ready(function () {
var lowerLimit = 0;
var upperLimit = 0;
function range(lowerLimit, upperLimit){
var lowerLimit = parseInt(prompt("What number would you like to begin with?"));
if (isNaN(lowerLimit)) {
alert("That's not a number, please retry.");
var lowerLimit = prompt("Please re-enter a number.");
}
var upperLimit = parseInt(prompt("What number would you like to end with?"));
if (isNaN(upperLimit)) {
alert("That's not a number, please retry.");
var upperLimit = prompt("Please re-enter a number.");
}
/* var arr = [upperLimit, lowerLimit, i];
for(i = 1; i <= (upperLimit - lowerLimit); i++){
var equation = lowerLimit + (lowerLimit+i);
}*/
//ends function
}
//ends document ready function
});
</script>