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.

JavaScript pls help me in coding

Kaun Gayn

Coder
function function1() {
var number = 1;
}
function function2() {
var number = 2;
}
function function3() {
if (number = 1) {
document.getelementbyid("num").innerhtml = 11;
}
if (number = 2) {
document.getelementbyid("num").innerhtml = 22;
}
}
 
I told you about global variables and local variables and you make the same mistake over and over.
The = equal sign assigns a value to a variable. The if() needs to look for equality and use the double equal sign ==
And AGAIN, you need to call your functions.
 
I told you about global variables and local variables and you make the same mistake over and over.
The = equal sign assigns a value to a variable. The if() needs to look for equality and use the double equal sign ==
And AGAIN, you need to call your functions.
i used double equal sign but it showing number is not defined.
can i do if (function1 == true)
 
Last edited:
i used double equal sign but it showing number is not defined.
Of course, it's not defined. Global and local variables. Study this page https://www.w3schools.com/js/js_scope.asp

Go and get an editor!!! I gave you URL for two. Use one! They would not have let you write 'document.getelementbyid("num").innerhtml = 11;' where you forget to capitalize letters. JS IS case sensitive.

And AGAIN, you need to call your functions.
 
Of course, it's not defined. Global and local variables. Study this page https://www.w3schools.com/js/js_scope.asp

Go and get an editor!!! I gave you URL for two. Use one! They would not have let you write 'document.getelementbyid("num").innerhtml = 11;' where you forget to capitalize letters. JS IS case sensitive.
i understood the global and local variables.
you know what i want to do. can you give me alternative of this coding
 
With everything I have given and shown you so far you should be able to do this on your own. Just stop, take a deep breath, and think about what you want to do. Ask yourself if you want functions and then code it. Give it a try and come back if you're still having problems. But please try
 
With everything I have given and shown you so far you should be able to do this on your own. Just stop, take a deep breath, and think about what you want to do. Ask yourself if you want functions and then code it. Give it a try and come back if you're still having problems. But please
is this working ?
function function1() {
var number = 1;
function function3() {
if (number = 1) {
document.getelementbyid("num").innerhtml = 11;
}
if (number = 2) {
document.getelementbyid("num").innerhtml = 22;
}
}
}
function function2() {
var number = 2;
function function3() {

if (number = 1) {

document.getelementbyid("num").innerhtml = 11;

}

if (number = 2) {

document.getelementbyid("num").innerhtml = 22;
}
}
}
 
is this working ? Don't you have a browser? And why haven't you learned to use the </> icon in the message box title bar above you and to the right???
Save your JS like this with the title test.html
Code:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta
        name="viewport"
        content="width=device_width, initial_scale=1.0;"
        charset="utf_8"
    />
    <style></style>
</head>
<body>
    <p id="num"></p>
<script>
    function function1() {
        var number = 1;
        function function3() {
            if ((number == 1)) {
                document.getElementById("num").innerHTML=11;
            }
            if ((number == 2)) {
                document.getElementById("num").innerHTML=22;
            }
        }
        function3();
    }
    function function2() {
        var number = 2;
        function function3() {
            if ((number == 1)) {
                document.getElementById("num").innerHTML=11;
            }
            if ((number == 2)) {
                document.getElementById("num").innerHTML=22;
            }
        }
        function3();
    }
    function2();
</script>
</body>
</html>
Then just save it on the desk top and drag and drop it into your browser.

I can just look at the code and see you're using functions and you don't call them - so NO it won't work.
Add to that you haven't downloaded an editor so NO it won't work.
 

New Threads

Buy us a coffee!

Back
Top Bottom