2

Using a website called JS Bin (https://jsbin.com) i am trying to code a quadratic formula solver and when i run my code it returns this:

<script>try {function solve(a, b, c) { 
var result = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); 
var result2 = (-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); 
return result + "<br>" + result2;
} catch (error) { throw error; }

here is the HTML:

<form> <input type="number" placeholder="A"> 
 <input type="number" placeholder="B">
 <input type="number" placeholder="C">
 <textarea rows="10" cols="60" placeholder="Your Output">

and here is the Javascript:

function solve(a, b, c) { 
var result = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); 
var result2 = (-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); 
return result + "<br>" + result2; 

I tried to find an answer online but i did not find anything helpful, can anyone help me with this? i want the code to just produce the output of the javascript into the textarea.

1
  • 1
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: How to create a Minimal, Complete, and Verifiable example (stackoverflow.com/help/mcve) Commented Oct 30, 2018 at 15:39

1 Answer 1

1

You should just close your <textarea> tag using </textarea>. Also, don't forget to close your solve function declaration with a curly bracket } at the end :

function solve(a, b, c) { 

var result = (-1 * b + Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); 

var result2 = (-1 * b - Math.sqrt(Math.pow(b, 2) - (4 * a * c))) / (2 * a); 

return result + "<br>" + result2; 
}
<form> <input type="number" placeholder="A"> 
 <input type="number" placeholder="B">
 <input type="number" placeholder="C">
 <textarea rows="10" cols="60" placeholder="Your Output"></textarea>
 </form>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.