Bebo Khouja Posted August 24, 2021 Share Posted August 24, 2021 So i have a code in my JavaScript but however it does not hide the text. Here is the code: var isDebug = "false"; if (isDebug = true) { var x = document.createElement("A"); var t = document.createTextNode("Debug is on"); x.appendChild(t); document.body.appendChild(x); } else { false } The HTML still says "Debug is on" to anyone. I restricted to developer only to see this Link to comment Share on other sites More sharing options...
Bebo Khouja Posted August 24, 2021 Author Share Posted August 24, 2021 Screenshot of it happening Link to comment Share on other sites More sharing options...
Ingolme Posted August 24, 2021 Share Posted August 24, 2021 Your first problem is that you are assigning the string "false" to the variable. Strings are always true unless they are empty. Remove the quotes if you want to use the boolean value false. var isDebug = false; The second problem is that, to compare values, you have to use the == operator. A single = will change the value of the variable. if (isDebug == true) { The content in your else statement is not doing anything. It doesn't make sense to just type a value in a line of code. I'm not sure what you intended to do by just writing false, so I can't replace it with anything. A working version of the code would look like this: var isDebug = false; if (isDebug == true) { var x = document.createElement("A"); var t = document.createTextNode("Debug is on"); x.appendChild(t); document.body.appendChild(x); } I left the "== true" in to show how the == operator works, but it is not necessary when testing boolean values and could be shortened to if (isDebug) { Link to comment Share on other sites More sharing options...
Bebo Khouja Posted August 24, 2021 Author Share Posted August 24, 2021 However after setting the value with the page it still don't appear. This is done by going to the Admin page Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now