Grade Calculator Concatenation JavaScript -


this question has answer here:

my syntax fixed code , running. having problems adding 2 numbers instead of program concatenating values. help, ben

var averagetotal = (grades[j]+averagetotal); 

here whole code.

var numberofgrades = prompt("how many grades want calculate?"); var countingvalue = 0; var grades = []; var tempgrade = 0; var averagetotal = 0; for(var i=0;i<=numberofgrades;i++){ if(countingvalue!=numberofgrades){     if(countingvalue==1){     var tempgrade= prompt("what "+(countingvalue+1)+"st grade?");     grades.push(tempgrade);     countingvalue++; }     else if(countingvalue!=1){     var tempgrade= prompt("what "+(countingvalue+1)+"th grade?");     grades.push(tempgrade);     countingvalue++;     } } else if(countingvalue==numberofgrades) {     for(var j=0;j<numberofgrades;j++){         var averagetotal = (grades[j]+averagetotal); // problem line         alert(j+" "+averagetotal); //checking values     } }   } alert(grades[0]); //just checking values alert(grades[1]); //checking values alert(averagetotal); alert("your average grade is: "+(averagetotal/numberofgrades)); 

you can add numbers represented strings in couple of ways in javascript.

to ensure you're dealing numbers, use number() in example

var x = '1'; var y = '2';  x + y === '12'; // true number(x) + number(y) === 3; // true 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -