DNA pairing challenge bug

DNA pairing challenge bug
0

#1

I have this code for the challenge:

var arrayOfUnpairedArrays = [];
var unpairedArray= [];
function pairElement(str) {
  unpairedArray = str.split('');
  while(unpairedArray.length>0){
    arrayOfUnpairedArrays.push(unpairedArray.splice(0, 1));
    
  }
  for(var i=0; i<arrayOfUnpairedArrays.length; i++){
    if(arrayOfUnpairedArrays[i][0]=="G"){
      arrayOfUnpairedArrays[i].push("C");
    }
    if(arrayOfUnpairedArrays[i][0]=="C"){
      arrayOfUnpairedArrays[i].push("G");
    }
    if(arrayOfUnpairedArrays[i][0]=="A"){
      arrayOfUnpairedArrays[i].push("T");
    }
    if(arrayOfUnpairedArrays[i][0]=="T"){
      arrayOfUnpairedArrays[i].push("A");
    }
  }
  return arrayOfUnpairedArrays;
}

pairElement("CTCTA");

When I run each of the inputs the output is correct! However, the system has an X for each of the requirements.
Thanks,
David Bond
P.S. for now I am just going to copy and paste the official solution and save what I currently have in a google doc


#2

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.


#3

By declaring your variables outside of the function scope, you are making them global variables.

The FCC test runner doesn’t cope well with globals, so put your two variables at the top inside the function and you’ll pass the challenge :slight_smile:


#4

Thanks! It worked :stuck_out_tongue: