Need Help with this code for Intermediate Algorithm scripting. Everything checks out except the "<>" string

function convertHTML(str) {
  // &colon;&rpar;
  let newstr = "";
  let htmlEnt = {
    '&': '&amp;',
    '<': '&lt;',
    ">": '&gt;',
    '"': '&quot;',
    "'": '&apos;'
  }
  for(let property in htmlEnt){
    if(str.includes(property)){
      newstr = str.replace(/&|<|>|"|'/g,htmlEnt[property]);
      console.log(newstr)
      return newstr;
      }
        
    }
  newstr = str;
  console.log(newstr);
  return newstr;
}

convertHTML("<>");

do you know what your function is returning and what it should return? I suggest you use the browser console for this
try to console log the function call so you are sure what the function is returning

I just did and it should return &lt;&gt; but instead it returns &lt;&lt; which isn’t what I wanted. for some reason its not recognising the “>” character.
But if the function call was:
convertHTML("Sixty > twelve")

It returns:
Sixty &gt; twelve

like it should and I don’t know why?

look at each line of your code, can you figure out which one is telling the code to do that?

I fixed it thanks, did it another way. and I got the result I wanted.

This was the correct code I came up with.

function convertHTML(str) {
  // &colon;&rpar;
  let newstr = "";
  let htmlEnt = {
    '&': '&amp;',
    '<': '&lt;',
    ">": '&gt;',
    '"': '&quot;',
    "'": '&apos;'
  }
  for(let property in htmlEnt){
    if(str.includes(property)){
      newstr = str.replace(/&|<|>|"|'/g,property => htmlEnt[property]);
      console.log(newstr)
      return newstr;
      }
        
    }
  newstr = str;
  console.log(newstr);
  return newstr;
}

convertHTML("Dolce & Gabbana");

did you figure out what the issue was in your other code?

the replace() selects the first instance of a selected string and even with the global modifier it just repeats the same action on others like it.
This may work for other function calls but with the convertHTML("<>") it doesn’t because it takes the whole argument as a single string input.
So I set the new value to be replaced with an arrow function instead of selecting just the value of the property so it applies to each separately.

your replace is matching all the instances of the html entities, but then converting to the one from the loop.

could you do it without the loop?
considering that your loop is not going much…

you have solved the challenge but there are a few logical errors you could do without about the various features you are using

oh yeah! it worked without the loop and the if statement. Thanks!