Intermediate Algorithm Scripting - DNA Pairing

Why does this not work?

Your code so far

function pairElement(str) {
  let newArr=[]
  let newArr1=[]
  for (let i=0;i<=str.length;i++)
  if(str[i]==="A"||"T") {
newArr.push(str[i])
return newArr
  }
  for (let j=0;j<=str.length;j++)
  if(str[j]==="G"||"C"){
newArr1.push(str[j])
return newArr1
  }

}

console.log(pairElement("GCG"));

Your browser information:

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

Challenge: Intermediate Algorithm Scripting - DNA Pairing

Link to the challenge:

What does your output look like when you run a test case?

We can work backwards from there.

Thanks.
It just says
[ ‘G’ ]

So you have two problems.

  1. you are pushing one letter instead of a pair of letters

  2. you are stopping after the first letter of the input

1 Like

Okay I’ll try and understand the solution

You shouldn’t copy the answer. That doesn’t help you learn how to code. That only helps you read other people’s answers.

Look at the issues one at a time.

How can you fix the fact that you are only pushing one letter instead of two?