Creating Strings using Template Literals

Tell us what’s happening:

I’ve tried hard coding for this challenge, but I’m getting “Invalid regular expression flags” in the console and “Template strings were used” as unsatisfied(a grey cross). Please help.

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

you should not hard-code the strings 3 times
you should use a for-loop to loop over the input parameter ‘arr’ and print out the strings

finally, the error “invalid regular expression flags” is a known bug. So if you only have that one error, you can skip the challenge for now.

You might find some help if you look into Array.prototype.map() usage.

Yeah I tried the loops too. Still getting the same error. I’m able to form the array but these two errors so to speak are persistent.

i’m gonna try that and keep you posted.

please show your latest code.

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 => <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);

you forgot to put the backticks (string literals need backticks)

idk for some reason they didn’t get copied here, but there are backticks in my code

ok so you should be down to only one error now. That final error is a bug in FCC, so skip the challenge for now.

Can you try it in another browser for once…just in case

Yeah I’m at this right nowfcc2

FCC isn’t working one bit on MS Edge

ok so you can skip the challenge now and come back at some later point when hopefully the issue is fixed (this is not a browser issue btw)

Okay thank you. You’ve been of great help :slight_smile:

1 Like