freeCodeCamp/freeCodeCamp

Escaping HTML entities

Open

#63,788 opened on Nov 12, 2025

View on GitHub
 (22 comments) (0 reactions) (0 assignees)TypeScript (44,572 forks)batch import
help wanted

Repository metrics

Stars
 (444,744 stars)
PR merge metrics
 (Avg merge 6d 11h) (253 merged PRs in 30d)

Description

Describe the Issue

We have a challenge that asks campers to replace symbols like & with the relevant HTML entity &. It's a neat little challenge, BUUUUUUT...

The in-app console we render sanitises the entities back to HTML. So with correct code, campers still see & instead of &.

https://imgur.com/a/xxjSSW2

Affected Page

https://www.freecodecamp.org/learn/full-stack-developer/lab-html-entitiy-converter/implement-an-html-entity-converter

Steps to Reproduce

  1. Go to https://www.freecodecamp.org/learn/full-stack-developer/lab-html-entitiy-converter/implement-an-html-entity-converter
  2. Enter the following code.
  3. Open browser console.
  4. See different results.
function convertHTML(str) {
  let newStr = "";
  for (let char of str) {
    if (char == "&") {
      newStr += "&";
    } else if (char == "<") {
      newStr += "&lt;";
    } else if (char == ">") {
      newStr += "&gt;";
    } else if (char == '"') {
      newStr += "&quot;";
    } else if (char == "'") {
      newStr += "&apos;";
    } else {
      newStr += char;
    }
  }
  return newStr;
}

console.log(convertHTML("Dolce & Gabbana"));

Expected behavior

The in-app console should render `Dolce & Gabanna

Screenshots

No response

System

Irrelevant

Additional context

https://www.reddit.com/r/FreeCodeCamp/comments/1ovgdgm/current_javascript_version_autoconvert_makes/

Contributor guide