DNA Pairing, problem it's correct but?

Hi everybody

I have a problem with this challenge, it seems to be correct because when I test it on the developer tool console it works but on FCC console doesn’t work, where do you think the problem is?

here is the code:


function pairElement(str) {
  let toArr = str.split("");
  let newArr = [];
  for(let i = 0; i < str.length; i++){
    if(toArr[i] === "C" || toArr[i] === "G"){
      if(toArr[i] === "C"){
        newArr.push(["CG"]);
      }else{
        newArr.push(["GC"]);
      }
    }
    if(toArr[i] === "A" || toArr[i] === "T"){
      if(toArr[i] === "A"){
        newArr.push(["AT"]);
      }else{
        newArr.push(["TA"]);
      }
    }
  }
  return newArr;
}

pairElement("GCG");

here is it again but doesn’t work again


function pairElement(str) {
  let toArr = str.split("");
  let newArr = [];
  for(let i = 0; i < str.length; i++){
    if(toArr[i] === "C" || toArr[i] === "G"){
      if(toArr[i] === "C"){
        newArr.push(["C", "G"]);
      }else{
        newArr.push(["G", "C"]);
      }
    }
    if(toArr[i] === "A" || toArr[i] === "T"){
      if(toArr[i] === "A"){
        newArr.push(["A", "T"]);
      }else{
        newArr.push(["T", "A"]);
      }
    }
  }
  console.log(newArr);
}

pairElement("GCG");

@ansdb Your function needs a return statement (instead of just a console.log statement).

1 Like

Yes i don’t pay attention to that, thank you so much for your help i have one question for you

is my code can be considered as a best practice or clever code or there is other ways to write code more organized, short and fast than mine?

Yes you’re right, thank you so much mr @camperextraordinaire for your help :slight_smile: