DNA Pairing problem

Tell us what’s happening:
wher m getting wrong?

Your code so far

function pairElement(str) {
  var res=[];
  arr=str.split("");
  for(i=0;i<arr.lenght;i++){
    switch(arr[i]){
      case "A": res[i].push(arr[i]);
                res[i].push("T");
                break;
      case "T": res[i].push(arr[i]);
                res[i].push("A");
                break;
      case "C": res[i].push(arr[i]);
                res[i].push("G");
                break;
      case "G": res[i].push(arr[i]);
                res[i].push("C");
                break;
    }
  }
  return res;
}

pairElement("TCG");

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.139 Safari/537.36.

Link to the challenge:
https://www.freecodecamp.org/challenges/dna-pairing

  1. lenght
  2. the first push in each case statement: you’re trying to push to a nonexistent thing (there is no element at res[i] to push to). Second push in each case statement is fine.

thanx for that “lenght” thing…but how to declare a 2d array in js?

You’ve already just about done it, you need to push the array into the res array, res[i] doesn’t exist when you first try to do it on each case statement - res.push([arr[i])

m sorry i didn’t get u properly…can u please send me the code snippet

res.push([arr[i]) 
1 Like