I'm working on that piece of code which doesn't behave as I expected. Especially conditions. In console log I see that objekt.teamA is false, teamA is false, objekt.teamB is true, teamB is true but 1st condition is accepted without any reason.
Could anybody tell me why is that so?
function wsConnect()
{
var objekt =
{
teamA: document.getElementById('teamA').value,
teamB: document.getElementById('teamB').value
};
console.log("connect",wsUri);
ws = new WebSocket(wsUri);
ws.onmessage = function(msg)
{
obj = JSON.parse(msg.data);
lightsAv = obj.lights;
doorsAv = obj.doors;
electricAv = obj.electric;
teamA = obj.teamA;
teamB = obj.teamB;
console.log(objekt.teamA + " " + teamA + " " + objekt.teamB + " " + teamB);
//objekt.teamA is false, teamA is false, objekt.teamB is true, teamB is true
if(objekt.teamA && !teamA)
{
console.log("1st condition");
}
if(objekt.teamB && !teamB)
{
console.log("2nd condition");
}
}
ws.onopen = function()
{
document.getElementById('status').innerHTML = "connected";
console.log("connected");
}
ws.onclose = function()
{
document.getElementById('status').innerHTML = "not connected";
setTimeout(wsConnect,3000);
}
}
Thanks a lot.