Hey guys, I just started learning JavaScript and I was wondering can someone help me with this little thing. I have the following line of code that needs to check a string for capital letters: var b=1; var reci="BOG otac"; var patt1=/[A-Z]/g; provera1 = patt1.test(reci.charAt(b-1)); provera2 = patt1.test(reci.charAt(b)); provera3 = patt1.test(reci.charAt(b+1)); document.write(provera2); Code (markup): The problem is that variables provera1 and provera3 are giving me true value, but provera2 is always giving me false. I don't know what I'm doing wrong, and I don't know why provera2 is giving me false value, so can somebody explain it to me?
you are using the test reversed. var b=1; var reci="BOG otac"; var patt1=/[A-Z]/g; provera1 = reci.charAt(b-1).test(patt1); provera2 = reci.charAt(b).test(patt1); provera3 = reci.charAt(b+1).test(patt1); Code (javascript):