var Range = new Array();
$("#IDbutton").click(function(){
var sum=0;
var startInput=$("#IDstartInput").val(); //ID of the starting number
var endInput=$("#IDendInput").val(); //ID of the ending number
var stepInput=$("#IDstepInput").val(); //ID of the step number
document.write("choosen range is between: " + startInput + " and " + endInput+ "<br> choosen step is: " + stepInput +"<br>");
var a = parseInt(startInput); //change string into integer
var b = parseInt(endInput);
var c = parseInt(stepInput);
if (a<b){
if (c>0){
for(counter=a; counter<=b; counter+=c){
Range.push(counter);
sum+=counter;
}
document.write("sum of all numbers is: " +sum);
}
else if (c==0){
document.write("wrong step");
}
else{ // if(c<0)
c=c*(-1);
for(counter=a; counter<=b; counter+=c){
Range.push(counter);
sum+=counter;
}
document.write("sum of all numbers is: " +sum);
}
}
else { // if(a>b)
if (c>0){
for(counter=a; counter>=b;counter -= c){
Range.push(counter);
sum+=counter;
}
document.write("sum of all numbers is: " +sum);
}
else if (c==0){
document.write("wrong step");
}
else{ // if(c<0)
c=c*(-1);
for(counter=a; counter>=b;counter -= c){
Range.push(counter);
sum+=counter;
}
document.write("sum of all numbers is: " +sum);
}
}
document.write("
"+"this is the range: "+Range);
})