I'm trying to recreate a simple project I have in my fundamentals class to javascript (from C++) but sum doesn't add every time the for loop runs. All other parts are ok but sum just lists the numbers in the order I put them in. Any help is appreciated
var num = prompt("Please enter an integer");
var lrg = num;
var sml = num;
var avg = num;
var sum = num;
var cnt = 10;
function runMath () {
for (i = 1; i < 10; i++) {
var num = prompt("Please enter an integer");
if (num > lrg) {
lrg = num;
} else {
lrg = lrg;
}
if (num < sml) {
sml = num;
} else {
sml = sml;
}
sum += num;
}
}
runMath();
avg = sum/cnt;
promptreturns a string.parseInt()on the return value ofprompt.