1

I've got an issue with my code apparently..

function match2(string,pattern){
var patternUpper = pattern.toUpperCase(); // Change pattern to uppercase
var stringUpper = string.toUpperCase(); // Change string to uppercase
    for(var i=0;i<stringUpper.length-1;i++){
        if(stringUpper.indexOf(patternUpper.charAt(i))<0)
        return false;
    }
    return true;
}

Not sure why Firefox debugger is saying "pattern is undefined", seeing as it was defined in the function, right?

Any help is much appreciated.

Liam

EDIT: It is also doing this for string. Saying "string is undefined" if I comment out the second line of that snippet.

match2 is being called here:

alert(match2("thisisatest","ahtsit"));

The result works as expected, but the issue is causing errors further down in my program I think.

5
  • can you post the code where you are calling match2? Commented Nov 10, 2012 at 19:45
  • I'd assume you are not passing a second argument to match2, hence pattern.toUpperCase() will throw an error. The symbol pattern will exist, but if you don't pass an argument, it will have the value undefined. Commented Nov 10, 2012 at 19:45
  • it is working see jsfiddle.net/nKpce Commented Nov 10, 2012 at 19:52
  • I can see that it's working, but I'm still getting browser errors. I think this is causing a problem later in my code so need to fix this first. Commented Nov 10, 2012 at 19:53
  • Why my answer was wrong here? It's down voted and I don't know where is the mistake... :( Commented Nov 12, 2012 at 0:20

2 Answers 2

1

When "pattern" parameter is undefined, no matter where in which browser, it means that something is wrong with calling the function and you need to check the call stack, one step before inside the function and see what is going on there when you pass the parameters. (By the way, do not name the variables by using keywords or class names, I mean the variable named "string")

Hope it helps.

Cheers

Sign up to request clarification or add additional context in comments.

1 Comment

thx. in my case something was wrong with the function call. had to pass an object instead of string
0

It can only happen if you don't pass the second argument or the second argument is undefined

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.