This question is an exact duplicate:

The site has a timer

<div class="timer">1100</div> 

player's nickname

 <div class="myanme">MyNick</div> 

I catch a timer

 function find_timer() { var div_timer = document.getElementsByTagName('div'); for (var i = 0; i< div_timer.length; i++) if(div_timer[i].className == "tttimer") return timer_element = div_timer[i]; } 

Nick

 function find_myname() { var div_name = document.getElementsByTagName('div'); for (var i=0; i< div_name.length; i++) if(div_name[i].className == "myanme") return name_element = div_name[i]; } 

How to make the right condition for if?

 var value = parseInt(timer_element.innerHTML); var myname = "Nick"; var value2 = toString.name_element; // может и не правильно тяну ник.... if(((value2 = myname) && (value=15))) {} 

want:

if ((the variable monik coincided with the nickname is now on the site) and (timer value = 15)), then {..}

in fact, the other nicknames also launch part of {.}

Reported as a duplicate at Grundy. javascript 23 Dec '16 at 7:00 .

This question has been marked as a duplicate of an existing one.

    1 answer 1

     (value2 = myname) && (value=15) 

    There is an assignment, not a comparison.
    It should be like this:

     (value2 === myname) && (value === 15) 
    • Right, well, with value === 15 probably not critical? But I still care about var value2 = toString.name_element; Is everything all right here? - J. Doe
    • No, you have it all bad. name_element - will be an HTMLElement, not its contents, this time. Second, the toString method must be called as name_element.toString() . But you asked about the condition, I told you about the condition. - Sublihim
    • thanks for answers! link Help then with this part of the link. How rum there wanted to ask it, but did not know how to properly call it all. - J. Doe
    • In your example (only in the one that you described), it would be more correct to at least return as return div_timer[i].innerHTML . Make return timer_element = div_timer[i]; (i.e., for some reason, assigning a variable and immediately returning it is meaningless). InnerHTML will return the string to you and then do toString() - no need. And more advice, read about client JavaScript. - Sublihim
    • Those. var value2 = name_element.innerHTML; and (value2 === myname) to do so and there will be happiness? - J. Doe