Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

HTML pls help me in coding

Kaun Gayn

Coder
what's wrong in this coding ?

<!DOCTYPE html >

<html>
<body>
<h1 id= word> hello <h1>
<button onClick = "myFunction()"> click here <button>
<script>
var variable1 = Hi world
function myFunction() {
if (true) {
document.getElmentById("word").innerHTML = variable1;
}
</script>
</body>
</html>
 
var variable1 = Hi world
is a variable and needs to be in quotes. and always end a statement with a semicolon The ';'.
var variable1 = "Hi world";

For the second, you need to end your function with a curly bracket '}'
Your spelling is bad
document.getElmentById("word").innerHTML should be
document.getElementById("word").innerHTML a missing 'e'.

' if (true) {...}' makes no sense. It would always be true and has more characters than this example needs. You always try to use the least amount of characters. I removed it and it's ending }.

In your HTML You need to end the button tag with '</button>' Notice the forward slash '/'
Use 'onclick' not 'onClick'.
IDs need to be in quotes: <h1 id="word">

Look for a free editor that will help you like Notepad++or VScode

Code:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title></title>
 <style></style>
  </head>

<body>
    <body>
    <h1 id="word"> hello <h1>
    <button onclick = "myFunction()"> click here </button>

    <script>
    var variable1 ="Hi world";
    function myFunction() {
        if(true){
            /* document.getElmentById("word").innerHTML = variable1; */
            document.getElementById("word").innerHTML = variable1;
        }
    }
    </script>
    </body>
    </html>
 

New Threads

Latest posts

Buy us a coffee!

Back
Top Bottom