# Convert HTML Entities | Problem with if-else

**URL:** <https://forum.freecodecamp.org/t/convert-html-entities-problem-with-if-else/309561>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [August 27, 2019, 10:50am UTC](https://forum.freecodecamp.org/t/convert-html-entities-problem-with-if-else/309561 "2019-08-27T10:50:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eslam](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@eslam](https://forum.freecodecamp.org/u/eslam)\
**Post date:** [August 27, 2019, 10:50am UTC](https://forum.freecodecamp.org/t/convert-html-entities-problem-with-if-else/309561/1 "2019-08-27T10:50:25Z")

</div>

Hi, all

I’m trying to figure my solution for the Algorithm Scripting | Convert HTML Entities challenge and since i like using if else to figure solution for this challenge i do it with it but, when i click Run test .. It doesn’t work !!!

this is my code :

```auto
function convertHTML(str) {

  let newstr = str.split('') 

  for (let i = 0; i < newstr.length; i++) {
    if (newstr[i] == '&') {
    newstr[i] = '&​amp;';
    }
    else if (newstr[i] == '<') {
    newstr[i] = '&​lt';
    }
    else if (newstr[i] == '>') {
    newstr[i] = '&​gt;'
    }
    else if (newstr[i] == '"') {
    newstr[i] = '&​quot;';
    }
    else if (newstr[i] == "'") {
    newstr[i] = '&​apos;';
    }
  }
  newstr = newstr.join('');
  return newstr;
}
console.log(convertHTML("Dolce & Gabbana")) // Dolce &​amp; Gabbana

```

> **[freeCodeCamp.org](https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities)**
>
> Learn to Code — For Free

Thanks 😊

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [August 27, 2019, 10:55am UTC](https://forum.freecodecamp.org/t/convert-html-entities-problem-with-if-else/309561/2 "2019-08-27T10:55:51Z")

</div>

> [@eslam](#):
>
> newstr[i] = ‘&​apos;’

if you have copied and pasted these there may be an hidden character in there, which is deleted but the tests and so the tests fail (next curriculum update this should be fixed)  
try deleting and typing them

---

<div class="post-metadata">

**Author:** ![eslam](https://avatars.discourse-cdn.com/v4/letter/e/67e7ee/32.png) [@eslam](https://forum.freecodecamp.org/u/eslam)\
**Post date:** [August 27, 2019, 11:16am UTC](https://forum.freecodecamp.org/t/convert-html-entities-problem-with-if-else/309561/3 "2019-08-27T11:16:11Z")

</div>

Yes, i copied it but,because when i wrote it directly … it didn’t work and give me that in the console

```auto
console.log(convertHTML("Dolce & Gabbana")) // Dolce & Gabbana

```

OK , thanks. It’s work now 😀

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 25, 2021, 12:19pm UTC](https://forum.freecodecamp.org/t/convert-html-entities-problem-with-if-else/309561/4 "2021-01-25T12:19:30Z")

</div>

Closed on January 25, 2021, 12:19pm UTC


