DNA Pairing - code works in codepen.io but does not pass FCC tests

DNA Pairing - code works in codepen.io but does not pass FCC tests
0.0 0

#1
var arr = [];
function pairElement(str) {
  for (i=0;i<str.length;i++){
    switch (str[i]){
      case "A":
        arr.push(["A","T"]); 
        break;
        case "T":
        arr.push(["T","A"]); 
        break;
        case "C":
        arr.push(["C","G"]); 
        break;
        case "G":
        arr.push(["G","C"]); 
        break;
                  }
  }

  return arr;
}


pairElement("GCG");

#2

Your solution won’t pass unless you move arr inside the pairElement function. Code with global variables generally won’t pass in the challenges.


#3

That did the trick, thanks. Are we told that anywhere or is it something you figured out>


#4

I don’t think it’s stated somewhere (correct me if I’m wrong). But lots of people ask the question when they do the same.