# DNA Pairing not returning the right thing?\[SOLVED\]

**URL:** <https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746>\
**Category:** General\
**Created:** [July 28, 2017, 1:59pm UTC](https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746 "2017-07-28T13:59:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![calinwebdev](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/calinwebdev/32/60150_2.png) [@calinwebdev](https://forum.freecodecamp.org/u/calinwebdev)\
**Post date:** [July 28, 2017, 1:59pm UTC](https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746/1 "2017-07-28T13:59:36Z")

</div>

Hi guys, I don’t know what’s going on with my code. I seem to return the right thing but it doesn’t pass the challange.

```auto
function pairElement(str) {
  var array = [];
  var singleElement = str.split("");
  singleElement.forEach(function(dna){
    var temporaryArray = [];
    if(dna == "G"){
	      temporaryArray.push("G");
	      temporaryArray.push("C");
	      array.push(temporaryArray);
    } else if(dna == "C"){
	      temporaryArray.push("C");
	      temporaryArray.push("G");
	      array.push(temporaryArray);
    } else if(dna == "A"){
	      temporaryArray.push("A");
	      temporaryArray.push("T");
	      array.push(temporaryArray);
    } else if(dna == "T"){
	    temporaryArray.push("T");
	    temporaryArray.push("A");
	    array.push(temporaryArray);
    }
  });
}

pairElement("ATCGA");

```

Any suggestions?

---

<div class="post-metadata">

**Author:** ![mgjean](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/mgjean/32/58605_2.png) [@mgjean](https://forum.freecodecamp.org/u/mgjean)\
**Post date:** [July 28, 2017, 2:05pm UTC](https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746/2 "2017-07-28T14:05:07Z")

</div>

Try like this,  
`if (dna=="G") {Array.push(["G","C"])}`

---

<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:** [July 28, 2017, 2:11pm UTC](https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746/3 "2017-07-28T14:11:28Z")

</div>

Your code works except you forgot to return the array at the end. And you could have pushed an array literal directly without the need for `temporaryArray` like @mgjean said.

---

<div class="post-metadata">

**Author:** ![calinwebdev](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/calinwebdev/32/60150_2.png) [@calinwebdev](https://forum.freecodecamp.org/u/calinwebdev)\
**Post date:** [July 28, 2017, 2:12pm UTC](https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746/4 "2017-07-28T14:12:40Z")

</div>

I feel so stupid now. I’m a little tired but really there’s no excuse for this. Thanks for your quick input guys!

---

<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 17, 2021, 8:47pm UTC](https://forum.freecodecamp.org/t/dna-pairing-not-returning-the-right-thing-solved/138746/5 "2021-01-17T20:47:07Z")

</div>

Closed on January 17, 2021, 8:47pm UTC


