Dna challenge problem with quotes

Tell us what’s happening:
Hello, I wrote this code for the DNA challenge , it seems to work perfect in Scrimba(see: https://scrimba.com/c/cWKZLys2 ), the results for each combination of strings was correct. But, for some reason that I don’t understand, on FreeCodeCamp page the results come with single quotes instead of double quotes, and I think that is the problem for pass this challenge. Please if any of us can help me with this, I than you very much. Regards!!

Your code so far

var arr0=[];
function pairElement(str) {
for (let i=0;i<str.length;i++){
 if (str.charAt(i)=="A"){
arr0.push(["A","T"]);  }
else if (str.charAt(i)=="C"){
arr0.push(["C","G"]);  }
else if (str.charAt(i)=="G"){
arr0.push(["G","C"]);  }
else if (str.charAt(i)=="T"){
arr0.push(["T","A"]);  }}
return arr0;}
//Si A, el par es AT
//Si C, el par es CG
//Si G, el par es GC
//Si T, el par es TA

Your browser information:

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

Challenge: DNA Pairing

Link to the challenge:

Single quotes vs double quotes doesn’t matter. Those just indicate that something is a string.

1 Like

Why is your arr0 defined outside of the body of function pairElement?

1 Like

Thank you for you reply, yes, you’re right, but it’s the only difference that I can see, and don’t matter if I use single or double quotes, on console log display single quotes when expected double, according to the solution offered by fcc. Any suggestion? Regards! :grin:

Your code contains global variables that are changed each time the function is run. This means that after each test completes, subsequent tests start with the previous value. To fix this, make sure your function doesn’t change any global variables, and declare/assign variables within the function if they need to be changed.


var myGlobal = [1];
function returnGlobal(arg) {
  return myGlobal;
} // unreliable - array gets longer each time the function is run

function returnLocal(arg) {
  var myLocal = [1];
  return myLocal;
} // reliable - always returns an array of length 2
1 Like

Good point,I forgot that it’s not recommended, but that has worked…:thinking:

Yes, has worked by changing arr0 to local variable!!! The quotes still are single, but as you has commented, this is irrelevant.Thank you very much, Ariel!!! :muscle: :muscle: :smiley: :+1:

I’m glad I could help. Congratulations on working it out. Happy coding!

1 Like

Thank you very much for your help, Nick, you´re right way!!! Challenge passed! :smiley: :+1: :+1: