Red closing brackets?

Why are the closing angle brackets for several of my code blocks red? My code works without issue, but I still get these red brackets. What exactly are they trying to tell me? Can someone tell me how to fix them in this code example?

Usually this indicates that the closing bracket has no corresponding opening bracket, and is simply trailing the rest.

Though from your picture I count 5 opening brackets and only 4 closing.
Is this all of your code?
If you have more could you please post it, and also a link to the lesson?

Also strange, this usually throws an unexpected identifier error.

https://www.codecademy.com/practice/projects/mysterious-organism

// Returns a random DNA base
const returnRandBase = () => {
  const dnaBases = ['A', 'T', 'C', 'G'];
  return dnaBases[Math.floor(Math.random() * 4)];
}

// Returns a random single stand of DNA containing 15 bases
const mockUpStrand = () => {
  const newStrand = []
  for (let i = 0; i < 15; i++) {
    newStrand.push(returnRandBase())
  }
  return newStrand
}

const pAequorFactory = function(specimenNum, dna) {
  return {
    specimenNum: specimenNum,
    dna: dna,
    mutate(dna) {
      //Create an index to grab a random current base
      //Create a newBase string to hold a random new base
      let index = Math.floor(Math.random() * 15);
      console.log(index)
      let currentBase = this.dna[index];
      let newBase = ""
      //Call returnRandBase until newBase !== currentBase
      do {newBase = returnRandBase()}
      while (currentBase === newBase);
      //Update dna with the new base and return it
      this.dna[index] = newBase;
    },
    compareDNA(obj){
      //input - pAequor object('s dna array), and this.dna
      let ex1 = this.dna;
      console.log(ex1)
      let ex2 = obj.dna;
      console.log(ex2)
      let count = 0;
      for (let i = 0; i < ex1.length; i ++) {
        if (ex1[i] === ex2[i]) {
          count++;
        }
      }
      let percent = Math.round((count / 15) * 100)
      console.log(percent + "% shared DNA")
      return percent
      //output - percentage that represents how many bases are shared
    }
  }
}

let specimen1 = pAequorFactory(1, mockUpStrand());
let specimen2 = pAequorFactory(2, mockUpStrand());
specimen1.compareDNA(specimen2);

I’ve finally figured out what’s going on. Even though the code works without them, the browser is demanding a semicolon on every line. I’ve updated the code with more semicolons than what’s strictly necessary and it fixed everything.

2 Likes

You’ll find that JavaScript is a permissive language. It may not complain if you omit a semicolon which ought to be there, but that doesn’t make the omission necessarily correct. :slight_smile:

I’m having this issue, too. I’m in the “Re-creating the Lo-Dash library,” specifically on the _has method. Here’s a snippet.

 },
 has: function(objectVar, keyVar) {
   let hasValue = Boolean(objectVar[keyVar]);
   return hasValue;
 },

 invert: function(objectVar) {

https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/pjs-javascript-capstone/projects/lodash

Have you tried what was listed above?
Make sure that every closing bracket has a corresponding opening bracket, and that you are using semicolons correctly.

Every bracket has a mate, and every line has a semicolon (at least as far as I can determine).

Can you post a screenshot?
If it is the correct answer please use the hide details.

I’m sorry if this is a stupid question, but what do you mean by hiding the details? Is that the … thing? But I don’t see a way to do that in the Codecademy editor.

If you click the little gear, it gives you the option to “hide details”

like this

Summary

This text will be hidden

Okay, here’s the screenshot.

Summary

Since I don’t see your full code I can’t be certain, but are you sure you used commas in all the right spots as opposed to semicolons?

I believe if you had used them incorrectly it would throw an error…

Yeah, comma after every method in the object, not semicolons.

I put the whole code here if you want to look.

Summary
const _ = {

 clamp: function (num, lowerBound, upperBound) {

  let lowerClampedValue = Math.max(num, lowerBound);

  let clampedValue = Math.min(lowerClampedValue, upperBound);

  return clampedValue;

 },

inRange: function (num, startValue, endValue) {

  if (endValue === undefined) {

    endValue = startValue;

    startValue = 0;

  }

  if (startValue > endValue) {

    let tempValue = endValue;

    endValue = startValue;

    startValue = tempValue;

  }

  let isInRange = Boolean(startValue <= num && num < endValue);

  return isInRange;

},

words: function (string) {

   const wordArray = string.split(" ");

   return wordArray;

},

pad: function (string, lengthDesired) {

  if (string.length > lengthDesired) {

    return string;

  } else { 

    let frontPadding = Math.floor((lengthDesired - string.length)/2);

    let endPadding = lengthDesired - string.length - frontPadding;

    for (let i = 0; i < frontPadding; i++) {

      string = " " + string;

    }

    for (let i = 0; i < endPadding; i++) {

      string = string + " ";

    }

return string;

  }

},

has: function(objectVar, keyVar) {

  let hasValue = Boolean(objectVar[keyVar]);

  return hasValue;

},

invert: function(objectVar) {

  let invertedObject = {};

  for (const prop in objectVar) {

     invertedObject[objectVar[prop]] = prop;

  };

  return invertedObject;

},

findKey: function(objectVar, predFunction) {

  for (const prop in objectVar) {

    if (predFunction(objectVar[prop])) {

      return prop;

    } 

    else return undefined;

  }

},

drop: function(array, numToDrop = 1) {

  for (let i = 0; i < numToDrop; i++) {

    array.shift();

  }

  return array;

},



dropWhile: function(array, predFunction) {

 for (let i = 0; i < array.length; i++) {

   if (predFunction(array[i], i, array) === "true") {

     array.shift();

   } else {

     return array;

   }

}

}

};

// Do not write or modify code below this line.

module.exports = _;

I’s still looking at the code, but so far I can not figure out why it is doing that.
Perhaps someone who has more experience in JavaScript than I do like @midlindner could shed some more light on the matter.

I’m guessing it has something to do with line 44. I got another similar red bracket later in a similar situation.

Try adding semicolons after all the closing brackets except for the ones at the end of each function which should be followed by commas like they are already.

1 Like