Implement an HTML Entity Converter

I have no idea why this doesn’t pass the tests.

Exercise:
Implement an HTML Entity Converter: Implement an HTML Entity Converter | freeCodeCamp.org

This is Javascript only:

const convertHTML = (string) => {
  let newStr = string
    .replaceAll("&", "&")
    .replaceAll("<", "&amp;lt;")
    .replaceAll(">", "&amp;gt;")
    .replaceAll("'", "&amp;quot;")
    .replaceAll('"', "&amp;apos;");
  return newStr;
}

When I do a console.log to test my function, all tests work. But I keep getting a notification that I’m passing none of the tests (except 1. You should have a convertHTML function. and 8. convertHTML("abc") should return the string abc )

I don’t think this is exactly what is supposed to be substituted.

These are the tests vs. what I’m getting in console.log

1 and 8 pass the test, all other’s fail despite being equal to what is asked.

// The Tests
// 1. You should have a convertHTML function. - Passes the test
// 2. convertHTML("Dolce & Gabbana") should return the string Dolce &amp; Gabbana.
console.log(convertHTML("Dolce & Gabbana")); // returns: Dolce &amp; Gabbana
// 3. convertHTML("Hamburgers < Pizza < Tacos") should return the string Hamburgers &lt; Pizza &lt; Tacos.
console.log(convertHTML("Hamburgers < Pizza < Tacos")); // returns: Hamburgers &lt; Pizza &lt; Tacos
// 4. convertHTML("Sixty > twelve") should return the string Sixty &gt; twelve.
console.log(convertHTML("Sixty > twelve")); // returns: Sixty &gt; twelve
// 5. convertHTML('Stuff in "quotation marks"') should return the string Stuff in &quot;quotation marks&quot;.
console.log(convertHTML('Stuff in "quotation marks"')); // returns: Stuff in &quot;quotation marks&quot;
// 6. convertHTML("Schindler's List") should return the string Schindler&apos;s List.
console.log(convertHTML("Schindler's List")); // returns: Schindler&apos;s List
// 7. convertHTML("<>") should return the string &lt;&gt;.
console.log(convertHTML("<>")); // returns: &lt;&gt;
// 8. convertHTML("abc") should return the string abc. - Passes the test

Please read my post again. What are you supposed to replace & with?

2 Likes

Thank you! I was adding that extra & to get it to display in the console log as an entity, but that didn’t seem to matter.

1 Like