continuous user input in applab?

100 Views Asked by At

So I am working on an app on code.org that takes the users subject score, tells him what grade he has and in the end gives him the average score on all subjects. But the problem is that I am limited to (in my case) 4 subjects only, since for the code to run for each separate subject I have to click a button. I was wondering if there was a way to prompt the user for input until he enters a string and after that calculate the average total for all the subjects he entered? current code link: https://studio.code.org/projects/applab/uj3FPnbsFzmCO5UK3a0WnM3wsO1zTwl0-SLRP5VPrBw

1

There are 1 best solutions below

0
On

there's a simple fix to this.

var gpa1 = prompt("Input your first GPA");
var gpa2 = prompt("Input your second GPA");
var gpa3 = prompt("Input your third GPA");
var gpa4 = prompt("Input your fourth GPA");
var gpa5 = prompt("Input your fifth GPA");

if(gpa1>100){
  gpa1 = 100;
  console.log(gpa1);
} if(gpa2>100){
  gpa2 = 100;
  console.log(gpa1);
} if(gpa3>100){
  gpa3 = 100;
  console.log(gpa1);
} if(gpa4>100){
  gpa4 = 100;
  console.log(gpa1);
} if(gpa5>100){
  gpa5 = 100;
  console.log(gpa1);
}

After you add this you would want to call the variable gpa1, gpa2, gpa3, gpa4, and gpa5 when creating their total average. Also I included the if statements so you are not having an impossible gpa total, this is removable or changeable.