-1

So... I am trying something pretty ambitious (at least for myself). I am having difficulty finding a specific command or line of code that will do the following in HTML5

<body>
<p> The square root will go underneath </p> <input id="Number"><button onclick="ARE_YOU_SERIOUS">Check it</button>
<p id="Place Holder"></p>

<script>
    function ARE_YOU_SERIOUS()   
var x = document.getElementbyId("Number").value
       document.getElementbyId("Place_Holder").innerhtml = SQUARE ROOT(x)
    </script>

I do not want to calculate the square root of x, I just want to print a square root that will contain x in a specific placeholder

VALUES I WANT TO SEE!

  • Provide a [mcve] – Asons Nov 17 '18 at 21:29
  • How much more basic do you want me to get, I just want to print a sqrt(x) as a sqrt(x) with the radical and the x inside of it, but I will try to make a minimal code – Alex Carlson Nov 17 '18 at 21:35
  • So we understand what it is you ask. And `document.getElementbyId("Number").value` return the input value as a `string`, not a `number`, so you might want to do e.g. `SQUARE ROOT(parseInt(x))` – Asons Nov 17 '18 at 21:43
  • I have added a image of 2 different EXAMPLES of what I would like to see after running the script – Alex Carlson Nov 17 '18 at 21:50
  • Your code sample is full with syntax error, but when fixed, combined with what I stated in my 2nd comment, it count the square root just fine. – Asons Nov 17 '18 at 21:59
  • So just saying document.getElementbyId("Place_holder").innerhtml = SQUARE ROOT(x) will output a literal square root of x.... – Alex Carlson Nov 17 '18 at 22:02
  • 1
    You can't do this with just Unicode characters, you need something like MathML. See for example [this question](https://stackoverflow.com/q/12431339/238704) and its answers. – President James K. Polk Nov 18 '18 at 00:51

2 Answers2

0

So after doing a wider range of testing on my series of coding, I realized that one of the only ways I could do what I wanted efficiently is to incorporate a library like MathJax. I ended up not getting the squareroot answer that I wanted right away because of line break issues and formatting but overall, mathjax fixed a significant amount of the pain I was feeling.

MathJAX does do radicals in the manner written it just takes some time.

-2

<script>
   var x = document.getElementbyId("Number").value;
   document.getElementbyId("Place_Holder").innerhtml = Math.sqrt(x);
</script>