r/learnjava • • Oct 05 '19

Quadratic Formula Practice program plz help

<!DOCTYPE html>

<html> <head> <meta charset="UTF-8"> <title>Quadratic Equation Practice</title> <style> </style> <script> let answer1 = 0; let correctNum = 0; let incorrectNum = 0;

function validate() {
a = document.forms["form1"]["a"].value;
b = document.forms["form1"]["b"].value;
c = document.forms["form1"]["c"].value;
if (a == 0) {
outputText = "Sorry, <em>a</em> cannot equal zero.";
} else if (isNaN(a)) {
outputText = "Sorry, <em>a</em> needs to be a number.";
} else if (isNaN(b)) {
outputText = "Sorry, <em>b</em> needs to be a number.";
} else if (isNaN(c)) {
outputText = "Sorry, <em>c</em> needs to be a number.";
}

function setup(){
resetEquation1();
}
function resetEquation1() {
let a = Math.floor(Math.random() * 10);
let b = Math.floor(Math.random() * 10);
let c = Math.floor(Math.random() * 10);
answer1 = (-b - Math.sqrt (Math.pow(b, 2) - 4 * a * c)) / (2 * a);
answer2 = (-b + Math.sqrt (Math.pow(b, 2) - 4 * a * c)) / (2 * a);
document.getElementById("eq1").innerHTML = "What is (-b + Math.sqrt (Math.pow(b, 2) - 4 * a * c)) / (2 * a)";

}
</script>

<p align="center">Use the Quadratic Equation to solve for a, b, and c. (Remeber the form <strong>ax\&#x00B2; + bx + c = 0</strong>)</p>

<br> <div id="submit-area"> <p align="center">Correct Answers: <span id="correct">0</span></p> </div>

<div id="submit-area"> <p align="center">Incorrect Answers: <span id="incorrect">0</span></p> </div>

</div> </head> <form align="center" name="form1" action="javascript:validate()"> a: <input type="text" name="a" size="4" required> b: <input type="text" name="b" size="4" required> c: <input type="text" name="c" size="4" required> <input type="submit"> </form> <p id="output_text"> </p> </html>

0 Upvotes

1 comment sorted by

4

u/[deleted] Oct 05 '19

That’s JavaScript. Not Java.