Very simple...
You set the value of a = 0;
and of var b = a == 0;
. At this time to shall have the value of 0 and b will have the value of true. Which shows the first values in inputs
.
After clicking the button, you are updating the value of to for a + 1
. However, you are not updating the value of b, because by clicking the button, it calls the function aoba()
, and is executed only that code below:
function aoba(){
document.getElementById('zbox').value=a;
document.getElementById('ybox').value=b;
a = a+1;
}
That is, at no time the value of the variable b is being updated.
To update the value of b, put it into the function aoba()
, in this way:
function aoba(){
var b = a == 0;
document.getElementById('zbox').value=a;
document.getElementById('ybox').value=b;
a = a+1;
}
Thus the value of b will be updated as you wish. The result can be seen in the code below:
var a = 0;
function aoba(){
var b = a == 0;
document.getElementById('zbox').value=a;
document.getElementById('ybox').value=b;
a = a+1;
}
<button id="a" value="b" onclick="aoba()" name="botão">I'm gonna crazy.</button>
<p>
<input type="text" id="zbox">
</p>
<input type="text" id="ybox">
Taking advantage, this list of questions offers great content to your doubt, directly or indirectly.
It should not appear false, that’s correct, when you create "b" the value of "a" is zero, then the value of "b" is true, and you do not change the value of "b" anywhere after that.
– Júlio Neto
When you ask a question like "it should happen" explain why you think it should happen. You can [Dit] the question.
– Maniero
Remove the image and put the real code to test.
– Guilherme Nascimento
I thought that every time b was accessed it would obligatorily check a and update the condition of true or false.
– Daniel De Santana Sforzim