Convert HTML Entities assistance

hey guys, may anyone please tell me why else if (smallBigReg.test(str)) { return str.replace(smallBigReg, '<>') } this code not passing? if I try to log it inside the if statement it doesn’t show as well, I am not sure why. Ty :slight_smile:

   **Your code so far**

function convertHTML(str) {
const andReg = /&/ig;
const smallerReg = /</ig;
const biggerReg = />/ig;
const doubleQuoteReg = /"/ig;
const aposReg = /'/gi;
const smallBigReg = /<>/ig;

if (andReg.test(str)) {
return str.replace(andReg, '&amp;');

else if (smallerReg.test(str)) {
return str.replaceAll(smallerReg, '&lt;');

else if (biggerReg.test(str)) {
  return str.replace(biggerReg, '&gt;');
else if (doubleQuoteReg.test(str)) {
return str.replace(doubleQuoteReg, '&quot;');
else if (aposReg.test(str)) {
return str.replace(aposReg, '&apos;');
else if (smallBigReg.test(str)) {
return str.replace(smallBigReg, '&lt;&gt;')
else if (str) {
  return str;

   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/101.0.4951.67 Safari/537.36

Challenge: Convert HTML Entities

Link to the challenge:

1 Like

because this is true first, and only the first true condition is executed in a if/else chain

Ah. Alright, thank you for the help :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.