Daily Coding Challenge - Markdown Heading Converter

Tell us what’s happening:

My code works if I open the browser console, but the test doesn’t work. The built-in console doesn’t show the HTML tags, I understand that.

Your code so far

function convert(heading) {
    const regex = /\s*#+\s+/;
    if (regex.test(heading)) {
      let numHash = heading.match("#+");
      if (numHash[0].length <= 6) {
        heading = heading.replace(regex, `<h${numHash[0].length}>`);
        heading = heading + `<h${numHash[0].length}>`;
      } else {
        heading = "Invalid format";
      }
      console.log(heading);
    } else {
      heading = "Invalid format";
      console.log(heading);
    }
  return heading;
}
convert("## My #2 heading"); 

Your browser information:

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

Challenge Information:

Daily Coding Challenge - Markdown Heading Converter
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-11-19

what does the second line in your if do?

Hello, it matches 1 or more cases of hashes (#) and puts it into a variable, then I extract the length of those hashes using length, and use as a heading number.

I mean this one

the first line does this

what does the second line do?

Sorry for misunderstanding.
heading = heading + `<h${numHash[0].length}>`;
This line concatenates a closing tag to the end.

are you sure? really really sure?
what are the characteristics of a closing tag?

1 Like

Thank you for your patience, I understood what I was missing out :nerd_face: