In my grading system, the maximum score is 100 and it is automatically calculated based on the input provided. The total score is read-only. I also want to display a brief feedback text depending on the total score without using a submit button. For instance, if the grade is 90 or below, the feedback should be set to 'Very Good', and if it's less than or equal to 80, the feedback will be 'Good'.
function calculateTotal(){
var scores = document.getElementsByName('qty');
var totalScore = 0;
for(var i=0;i<scores.length;i++){
if(parseInt(scores[i].value))
totalScore += parseInt(scores[i].value);
}
document.getElementById('total').value = totalScore;
}
function provideFeedback() {
var overallScore = document.getElementById("total").value;
var feedbackMessage;
if (overallScore >= 90) {
feedbackMessage = "OUTSTANDING";
} else if (overallScore >= 80) {
feedbackMessage = "VERY GOOD";
} else if (overallScore >= 70) {
feedbackMessage = "GOOD";
} else {
feedbackMessage = "Needs Improvement";
}
document.getElementById("feedback").value = feedbackMessage;
}
<div class="column3 tworow" style="background-color:#bbb;" align="center">
<table id="t01">
<tr>
<td>SCORE: <input type="text" name="total" id="total" style="text-align:center;font-size:20px" onkeyup="provideFeedback()" readonly></td>
</tr>
<tr>
<td>FEEDBACK: <input type="text" name="feedback" id="feedback" style="text-align:center;font-size:20px" readonly></td>
</tr>
</table>
</div>
I attempted to use different if/else statements in JavaScript but encountered issues with the syntax of the elseif function.