Create Strings using Template Literals, possible bug

Create Strings using Template Literals, possible bug
0

#1

Tell us what’s happening:
Is this a bug? Code below does everything that’s asked for and runs fine in visual studio. Yet it keeps throwing ‘invalid regular expression flags’. what’s happening?

Your code so far


const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
  "use strict";

  // change code below this line
  const resultDisplayArray = [`<li class="text-warning">${arr[0]}</li>`,
  `<li class="text-warning">${arr[1]}</li>`,
  `<li class="text-warning">${arr[2]}</li>`]; 
    
    
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ <li class="text-warning">no-var</li>,
 *   <li class="text-warning">var-on-top</li>, 
 *   <li class="text-warning">linebreak</li> ]
 **/
const resultDisplayArray = makeList(result.failure);

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/es6/create-strings-using-template-literals/


#2

It’s not a bug per se, just a condition that isn’t made clear but they expect to be implied because it’s best practice - they expect you to use a loop or map over the array instead or hard coding the three strings in.


#3

tried this below. still throws the same error.
const result = {
success: [“max-length”, “no-amd”, “prefer-arrow-functions”],
failure: [“no-var”, “var-on-top”, “linebreak”],
skipped: [“id-blacklist”, “no-dup-keys”]
};
function makeList(arr) {
“use strict”;

// change code below this line
const resultDisplayArray = arr.map((x) => {
return <li class="text-warning">${x}</li>;
});

// change code above this line

return resultDisplayArray;
}
/**

  • makeList(result.failure) should return:
  • [
  • no-var
  • ,
  • var-on-top
  • ,
  • linebreak
  • ]

**/
const resultDisplayArray = makeList(result.failure);


#4

Hi,

I think a bug was accidentally introduced recently (like yesterday maybe) in the last test case for this challenge. Best I can tell is a new regular expression was used to test if the strings in the array were valid. There appears to be something wrong with that regex though.

Someone had already opened an issue on the FCC GitHub so I just commented my observation and left it at that.


Create Strings using Template Literals - "Invalid regular expression flags"
#5

ah so it is a bug. Thank you.


#6

This is the test:

        {
          "text": "Template strings were used",
          "testString":
            "getUserInput => assert(getUserInput('index').match(/`<li \\s*class\\s*=\\s*(\"\\s*text-warning\\s*\"|'\\s*text-warning\\s*')\\s*>\\s*\\$\\s*\\{(\\s*\\w+\\s*|\\s*\\w+\\s*\\[\\s*[\\w]+\\s*\\]\\s*)\\}\\s*<\\s*\\/li\\s*>`/g), 'Template strings were used');"
        }

and the file was updated 2 days ago.

I don’t have the time to parse that regex - maybe someone smarter than me can.


#7

You definitely are not using a template literal with the code above. You must surround the string with backticks.


#8

strange those didn’t appear, I have them in my code (backticks) and double checked just now. Same problem.

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
  "use strict";

  // change code below this line
  const resultDisplayArray = arr.map((x) => {
    return `<li class="text-warning">${x}</li>`;
    });
    
    
  // change code above this line

  return resultDisplayArray;
}
/**
 * makeList(result.failure) should return:
 * [ <li class="text-warning">no-var</li>,
 *   <li class="text-warning">var-on-top</li>, 
 *   <li class="text-warning">linebreak</li> ]
 **/
const resultDisplayArray = makeList(result.failure);

#9

When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.

You are correct that you had them. The code was just not formatted for the forum.


#10

ha, it removed them again… seems like the forum messenger does not like them. :confused:


#11

I see, sorry. Will be sure to do that next time. Thank you.


#12

I fixed it for you. There is a known bug still being worked out for the tests.


#13

I got this problem still, so let me know when it will be fixed so I can go back and fix. I will donate 10 dollars if you guys fix this problem ;). I would give more but between jobs right now lol.