DNA Pairing - code not passing tests but it seems correct

Hi all,

I seem to be outputting the correct results for the ‘DNA Pairing’ challenge but it doesn’t pass the tests?

Anyone know what I’m doing wrong here? Please see my code below - thanks.[details=Summary]

var arr1 = [];
var arr2 = [];

function pairElement(str) {
  var strArr = str.split("");
  var i = 0;
  
  while (i < str.length) {
    
    switch(strArr[i]) {

     case "A":
      arr1 = ["A","T"];
      break;
    case "T":
      arr1 = ["T","A"];
      break;
    case "C":
      arr1 = ["C","G"];
      break;
    case "G":
      arr1 = ["G","C"];
      break;
    default:
      return "WTF?";
  }
    arr2.push(arr1);
    i++;   
  }
  return arr2;
}

pairElement("ATCGA");[/details]

Move the global variables inside the function. Tests fail when there are globals.

1 Like

Ah, cheers @kevcomedia. Thank