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

**URL:** <https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044>\
**Category:** General\
**Created:** [January 24, 2017, 1:00pm UTC](https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044 "2017-01-24T13:00:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![RayHamilton](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/rayhamilton/32/91068_2.png) [@RayHamilton](https://forum.freecodecamp.org/u/RayHamilton)\
**Post date:** [January 24, 2017, 1:00pm UTC](https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044/1 "2017-01-24T13:00:35Z")

</div>

```auto
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");

```

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [January 24, 2017, 1:05pm UTC](https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044/2 "2017-01-24T13:05:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![RayHamilton](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/rayhamilton/32/91068_2.png) [@RayHamilton](https://forum.freecodecamp.org/u/RayHamilton)\
**Post date:** [January 24, 2017, 8:39pm UTC](https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044/3 "2017-01-24T20:39:48Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [January 25, 2017, 1:30am UTC](https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044/4 "2017-01-25T01:30:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 5:11pm UTC](https://forum.freecodecamp.org/t/dna-pairing-code-works-in-codepen-io-but-does-not-pass-fcc-tests/80044/5 "2021-01-16T17:11:05Z")

</div>

Closed on January 16, 2021, 5:11pm UTC


