Hi guys, so I’m just having a hard time understanding the Match() method of Javascript..
I’m reviewing the codes made by greasemonkey developers; I found that that’s the best way to learn javascript because everything is hand coded, no jquery no libraries involved.
Here’s the code that I don’t understand.. I have basic knowledge okay.. Just help me understand this. prolly give me some explainations.. I’ll stick bits of codes..
Here, the result is an array.. So I can assume that a match operation returns an array.
Here’s the value of the header: “RGHCo”, Level 15 Tycoon
What is result[1]? and what is result[0]? Is result[2] available?
[CODE]header = document.getElementById(‘app8743457343_content’);
header = header.getElementsByTagName(‘h1’)[0].innerHTML;
var result = header.match(/”(.*)”, Level [0-9]+ (w+)/);
this.name = result[1];
this.type = result[2];
Here’s another code that I don’t understand:
In this code, you can see that we have delay variable. The delay variable holds a paragraph that have a jail string.
Then in the if statement, we can see that we changed the value of delay to parseFloat(delay[1]) + 0.01.. Now can you please tell me the value of delay[1]? If we parseFloat(delay) that will return NaN right? But we can see that the developer used the value of delay[1] then add 0.01 to it.
[CODE]divs = header.getElementsByTagName(‘p’);
for (var i = 0; i < divs.length; i++) {
var delay = divs[i].innerHTML.match(/jail in ([0-9.]+) hour/);
if (delay) {
delay = parseFloat(delay[1]) + 0.01;
this.jail_delay = Page.now + Math.floor(3600 * delay);
break;
}
Please help me understand this..
Thanks!!