I have this vars:
var LC = $('#a').text() >= document.querySelector("#content_value > div:nth-child(3) > div > form > table > tbody > tr:nth-child(2) > td:nth-child(3) > input[type=text]").value,
ES = $('#b').text() >= document.querySelector("#content_value > div:nth-child(3) > div > form > table > tbody > tr:nth-child(2) > td:nth-child(4) > input[type=text]").value,
VK = $('#c').text() >= document.querySelector("#content_value > div:nth-child(3) > div > form > table > tbody > tr:nth-child(2) > td:nth-child(5) > input[type=text]").value,
SPY = $('#d').text() >= document.querySelector("#content_value > div:nth-child(3) > div > form > table > tbody > tr:nth-child(2) > td:nth-child(6) > input[type=text]").value,
CL = $('#e').text() >= document.querySelector("#content_value > div:nth-child(3) > div > form > table > tbody > tr:nth-child(2) > td:nth-child(7) > input[type=text]").value;
I noticed that whenever there were 2 digits each variable returns true or false correctly. But when I get to the hundreds, the variables return false wrongly (I think).
For example for the var CL
if $('#e').text()
equals 64 and document.querySelector("#content_value > div:nth-child(3) > div > form > table > tbody > tr:nth-child(2) > td:nth-child(7) > input[type=text]").value
equals 3 returns true.
But if the first returns 164 and the second still 3 will return false.
I can’t understand why. Tried to google it but I didn’t find anything. I may not be looking for the right terms tho (sorry).
My javascript is not excellent, I learned it myself to automate some things that make my life easier. If anyone can help me, I’d be very grateful.
2
Answers
While it’s true that
164 > 3
resolved to true,'164' > '3'
resolves to false.You need to convert these strings to numbers first. Consider using parseInt for that, if they’re guaranteed to be integers. You could also use parseFloat or the Number constructor to convert a string to a number:
Cast the input values and text content to integers.
You can achieve this various ways:
+str
parseInt(str)
Number(str)