Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
Difference in actual and required output in freecodecamp exercise

I have been trying to code the following exercise on freecodecamp and I am getting the same string as is shown in desired output, but the test fails on the site.

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities

Code:

function convertHTML(str) {
    res = "";
    
    for (let i in str) {
        if (str[i] == '&') {
            res= res.concat("&");
        }
        else if (str[i] == '<') {
            res = res.concat("&lt;");
            
        }
        else if (str[i] == '>') {
            res = res.concat("&gt;");
            
        }
        else if (str[i] == '\"') {
            res = res.concat("&quot;");
        }
        else if (str[i] == "\'") {
            res = res.concat("&apos;");
        }
        else {
            res = res.concat(str[i]);
        }
    }
    return res;
}

What could be the source of error

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!