Clarissa M.
asked 02/21/21NEED HELP JAVA CODE ASAP
How do I find the average of the marks (may use parseInt() and print. There are 3 marks.
if average>= 90 then print "Awesome";
if average>= 80 then print "Very Good";
if average>= 50 then print "Ok";
if average less than 50 then print "Fail";
I use document.getElementById ("result)".innerHTML=;
1 Expert Answer

Patrick B. answered 02/21/21
Math and computer tutor/teacher
<!DOCTYPE HTML>
<HTML>
<label> 1st Mark </label> <input type="text" id="txtNum1"/><br>
<label> 2nd Mark </label> <input type="text" id="txtNum2"/><br>
<label> 3rd Mark </label> <input type="text" id="txtNum3"/><br>
<button type="button" onclick="CalcAvg()"> Calculate Average </button>
<script>
function CalcAvg()
{
alert("CalcAvg");
var iNumbuff1 = document.getElementById("txtNum1").value;
var iNumbuff2 = document.getElementById("txtNum2").value;
var iNumbuff3 = document.getElementById("txtNum3").value;
var regex=/^[0-9]+$/;
if (!iNumbuff1.match(regex)) { alert("Invalid input for num1"); return; }
if (!iNumbuff2.match(regex)) { alert("Invalid input for num2"); return; }
if (!iNumbuff3.match(regex)) { alert("Invalid input for num3"); return; }
var iNum1 = parseInt(iNumbuff1)
var iNum2 = parseInt(iNumbuff2)
var iNum3 = parseInt(iNumbuff3)
if (isNaN(iNum1))
{
alert('invalid data for num1 ');
}
else
{
alert('1st # is valid');
if (isNaN(iNum2))
{
alert('invalid data for num2');
}
else
{
alert(' 2nd # is valid');
if (isNaN(iNum3))
{
alert('invalid data for num3');
}
else
{
var avg = (iNum1+iNum2+iNum3)*1.000/3;
alert(" average is " + avg );
if (avg>=90) { alert("AWESOME!"); }
else if (avg>=80) { alert(" Very Good"); }
else if (avg>=50) { alert(" ok "); }
else { alert("FAIL"); }
}
}
}
}
</script>
</HTML>
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Clarissa M.
Both HTML and JAVA02/21/21