-8

I need to connect inputs with the three numbers When i write a=1 b=-3 and c=-4 and when i press the button --> to have a solution

function solve(a, b, c) {
    let x1 = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a);
    let x2 = (-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a);
    return "X1= " + x1 + ", X2= " + x2;
}
console.log(solve(1, -3, -4));
DimityrU
  • 11
  • 5
  • 1
    what does it mean to "to look like more complete "? Please explain your question so that other people can help you. Put yourself in our shoes - we can't read your mind – Avery Feb 19 '18 at 19:32
  • Add three `` elements and a ` – Vasan Feb 19 '18 at 19:58
  • 1
    Possible duplicate of [Using an HTML button to call a JavaScript function](https://stackoverflow.com/questions/1947263/using-an-html-button-to-call-a-javascript-function) – Juan Feb 19 '18 at 20:17

1 Answers1

0

I don't fully understand your question, but I'm guessing you want your solve() function to execute when a button is pressed. Here are three options:

window.onload = function() {

    var button = document.getElementById("button");

    // Method 1

    button.addEventListener("click", function() {
        alert("clicked1");
        solve(a, b, c);
        // ^ Insert Params ^ 
    });

    // Method 2

    button.onclick = function() {
        alert("clicked2");
        solve(a, b, c);
        // ^ Insert Params ^
    };
    
};
#button {
    width: 100px;
    height: 100px;
    background-color: green;
}
<!DOCTYPE html>
<html>
    <head>
    
    </head>
    <body>
        <div id="button"> <p>This is a button</p></div>
    </body>
</html>

I hope this solves your question.

Jojo
  • 409
  • 1
  • 6
  • 11
  • If this was the answer you were looking for, it is indeed a duplicate like @Juan said. – Jojo Feb 19 '18 at 21:14
  • Yes thats the one thing I also need to connect inputs with the three numbers When i write a= b= and c= and when i press the button --> to have a solution – DimityrU Feb 20 '18 at 17:26