Solution not working in FCC

Solution not working in FCC
0.0 0

#1

Tell us what’s happening:
this solution works but FCC test is not accepting. please help. Link: https://repl.it/@ridafatima15h1/Convert-HTML-Entities

Your code so far


///////////////////////////////////////////////////////
/**Exercise: Convert the characters &, <, >, " (double quote), and ' (apostrophe), in a string to their corresponding HTML entities. */
////////////////////////////////////////////////////////
/**Note:  Commented Out console.log() are for debugging only. */
//Function
function convertHTML(str) {
	/**Input */
	console.log("___________________________");
	console.log("Input string: ", str);

	/**Algorithm */
	str = str.replace(/\&+/g, "&​amp;");
	str = str.replace(/\<+/g, "&​lt;");
	str = str.replace(/\>+/g, "&​gt;");
	str = str.replace(/\"+/g, "&​quot;");
	str = str.replace(/\'+/g, "&​apos;");

	/**Output */
	console.log("Output string: ", str);
	console.log("___________________________");
  return str;
}

convertHTML("Dolce & Gabbana");
convertHTML("Hamburgers < Pizza < Tacos");
convertHTML("Sixty > twelve");
convertHTML('Stuff in "quotation marks"');
convertHTML("Schindler's List");
convertHTML("<>");
convertHTML("abc");

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/convert-html-entities


#2

Can you try it with the below snippet? It looks the same but it should work. Just copy paste.

function convertHTML(str) {
	/**Input */
	console.log("___________________________");
	console.log("Input string: ", str);

	/**Algorithm */
	str = str.replace(/\&+/g, "&amp;");
	str = str.replace(/\<+/g, "&lt;");
	str = str.replace(/\>+/g, "&gt;");
	str = str.replace(/\"+/g, "&quot;");
	str = str.replace(/\'+/g, "&apos;");

	/**Output */
	console.log("Output string: ", str);
	console.log("___________________________");
  return str;
}

#3

Hey! it does work! but I can’t figure out the problem. this function is exactly the same. Please explain.
And thank you so much!


#4

It’s very strange indeed! But I discovered that there was something weird with the & in your HTML characters. To see this, you can click between & and a in &amp; or between & and l in &lt; and then do backspace. You will notice that you need two backspaces to remove &. Its like there is some invisible character in there for which I do not know the explanation.


#5

What @Tomvbesaid, you have a character with encoding that isn’t understood inserted after the &. The actual character is a zero-width-space (the bytes E2 80 8B). It will probably have been introduced when copy-pasting between things.

If I paste into the JS scratchpad in Firefox (or most text editors), it’s pretty obvious (the red dot is a character it doesn’t understand):

23

And if I look at the &amp in a hex editor (I’ve highlighted the bytes that shouldn’t be there):

37

Just to try to figure out where this is coming from, are you moving between a text editor and the FCC editor?

Or have you copy/pasted the HTML character codes (&amp; etc) from somewhere? There might be dodgy encoding on the page they came from if so.


#6

The character encoding issues could also be coming from your device. I know that iPhones and iPads have settings that screw with quotation marks, and other built-in keyboards could cause problems as well.


#7

Hey @Tomvbe, @DanCouper, @ArielLeslie , Can repl.it cause the problem, cause I solve the problem there in order to save it, and then copy paste it here. I have a window laptop


#8

EDIT: I think I got it now…actually I copy pasted&lt; &gt; &apos; &quot; &amp from freecode camp tests section
:sweat_smile::sweat_smile:
sc

actually I always copy paste these tests in replit and for this tests I also copied these.

Thank you so much for helping guys…this problem drove me crazy. I changed &lt; &gt; &apos; &quot; &amp by self typing and it works


#9

Hey I was wondering why did not faced this issue while executing this code in replit which had this particular character passed all tests. Could it be because replit compiler ignored this character?