Not Accepting Solution

Tell us what’s happening:

Can anyone tell me why freeCodeCamp isn’t accepting this solution?

Your code so far


 function pairElement(str) {
  let localArr = [];
  for (letter of str) {
      if (letter === "G") {
          localArr.push(["G", "C"]);
      } else if (letter === "C") {
          localArr.push(["C", "G"]);
      } else if (letter === "A") {
          localArr.push(["A", "T"]);
      } else if (letter === "T") {
          localArr.push(["T", "A"]);
      }
  }
  return localArr;
} 

Your browser information:

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

Challenge: DNA Pairing

Link to the challenge:

What do the failing tests say?

try running the tests with the browser console open

ReferenceError: letter is not defined

Interesting. It works in Visual Studio Code w/ the quokka extension. And I know that I’ve used for (x of arr) in another exercise successfully. Wonder why it doesn’t work here?

It might be running in strict mode?

'use strict'
const test = "test"

for (iterator of test) {
  console.log(iterator);
}

VM166:4 Uncaught ReferenceError: iterator is not defined

Anyway you really should declare the variable (var/let/const)

2 Likes

Defining the variable worked. Thanks!

function pairElement(str) {
    let localArr = [];
    for (let letter of str) {
        if (letter === "G") {
            localArr.push(["G", "C"]);
        } else if (letter === "C") {
            localArr.push(["C", "G"]);
        } else if (letter === "A") {
            localArr.push(["A", "T"]);
        } else if (letter === "T") {
            localArr.push(["T", "A"]);
        }
    }
    return localArr;
  }