DNA Pairing - clumsy I know, but what's wrong when it does as asked?

DNA Pairing - clumsy I know, but what's wrong when it does as asked?
0.0 0

#1

Tell us what’s happening:

Your code so far

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

pairElement("CTCTA");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:


#2

Does almost what is asked.

You code returns
[“C,G”, “T,A”, “C,G”, “T,A”, “A,T”]
but this is what is expected
[[“C”,“G”],[“T”,“A”],[“C”,“G”],[“T”,“A”],[“A”,“T”]]


#3

Hi, thanks - so it does - I’m clearly an idiot. Back to the drawing board!


#4

You should push [“C”,“G”]


#5

Thanks JohnBackUP - I will do so :slight_smile:
function pairElement(str) {
var arr = str.split(’’);
var newArr = [];

for (var i = 0; i < arr.length; i++) {
switch (arr[i]) {
case ‘A’:
newArr.push([“A”,“T”]);
break;
case ‘T’:
newArr.push([“T”,“A”]);
break;
case ‘C’:
newArr.push([“C”,“G”]);
break;
case ‘G’:
newArr.push([“G”,“C”]);
break;
}

}

return newArr;
}

pairElement(“GCG”);


#6

You’re not and idiot! Another set of eyes is a great tool no matter what your doing.


#7

Did it work ?

(the code)


#8

Aww thank you alhazen1 :slight_smile:


#9

It did John-freeCodeCamp :slight_smile: