Creating Strings using Template Literals

Creating Strings using Template Literals
0.0 0

#1

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


#2

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.


#3

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


#4

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.


#5

i’m gonna try that and keep you posted.


#6

please show your latest code.


#7

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


#8

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


#9

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


#10

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.


#11

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


#12

Yeah I’m at this right now


#13

FCC isn’t working one bit on MS Edge


#14

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)


#15

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