Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The code that should write os where there is Answer

<html>
    <head>
        <title>Computer Science</title>
         <script type="text/javascript"> 
            function stringWord()
            {              
                document.getElementById(andr).innerHTML="os";                
            }
          </script>
    </head>
    <body>
        <button id="good" onClick="stringWord()">Click</button>
        <label id="andr">Answer</label> 
    </body>
</html>


What I have tried:

javascript code functions and document object model
Posted
Updated 14-Sep-19 10:05am
v2

1 solution

I bet if you used the debugger tools included in the browser you would see some exception along the lines of Undefined variable [andr]

Basically your function is calling for it (andr) as a variable; instead of a string
HTML
<script type="text/javascript"> 
function stringWord() {
  //  document.getElementById(andr).innerHTML="os";
  document.getElementById("andr").innerHTML="os"; 
}</script>
 
Share this answer
 
Comments
four systems 16-Sep-19 4:59am    
thancs

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900