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("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("'", "&quot;")
.replaceAll('"', "&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 & Gabbana.
console.log(convertHTML("Dolce & Gabbana")); // returns: Dolce & Gabbana
// 3. convertHTML("Hamburgers < Pizza < Tacos") should return the string Hamburgers < Pizza < Tacos.
console.log(convertHTML("Hamburgers < Pizza < Tacos")); // returns: Hamburgers < Pizza < Tacos
// 4. convertHTML("Sixty > twelve") should return the string Sixty > twelve.
console.log(convertHTML("Sixty > twelve")); // returns: Sixty > twelve
// 5. convertHTML('Stuff in "quotation marks"') should return the string Stuff in "quotation marks".
console.log(convertHTML('Stuff in "quotation marks"')); // returns: Stuff in "quotation marks"
// 6. convertHTML("Schindler's List") should return the string Schindler's List.
console.log(convertHTML("Schindler's List")); // returns: Schindler's List
// 7. convertHTML("<>") should return the string <>.
console.log(convertHTML("<>")); // returns: <>
// 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