javascript - Print a word in my code -


this question has answer here:

i trying add 2 numbers in javascript , using below code given @ stack overflow website.

i want print output of file result =. shows result without wordings before it. please let me know how display result result = $result$

    <html>   <body>     <p>click button calculate x.</p>     <button onclick="myfunction()">try it</button>     <br/>     <br/>enter first number:     <input type="text" id="txt1" name="text1">enter second number:     <input type="text" id="txt2" name="text2">     <p id="demo"></p>     <script>       function myfunction() {         var y = document.getelementbyid("txt1").value;         var z = document.getelementbyid("txt2").value;         var x = +y + +z;         document.getelementbyid("demo").innerhtml = x;       }     </script>   </body> </html> 

change line

    document.getelementbyid("demo").innerhtml = x; 

to

    document.getelementbyid("demo").innerhtml = 'result=' +x; 

as @marcell fülöp has pointed out, javascript , not java. there should heaps of information online know two.

just break down bit, document.getelementbyid("demo") gets element (in case paragraph) in html document has id of demo. .innerhtml = letting put ever value want inside of demoelement.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -