Daily Coding Challenge - HTML Attribute Extractor

Tell us what’s happening:

The console parse the output as html tag, not string literal.
For example,

const cannotSee = (input) => return input
console.log(cannotSee('<span>abc</span>'))

will print 'abc' not '<span>abc</span>'

This makes the answer hard to match the expectation.

Your code so far

function extractAttributes(element) {
  const s = element.trim()
  const re = /\s+([^\s=]+)=("[^"]*"|'[^']*')>/g
  return [].concat(...[...s.match(re)].map(m => [m[1], m[2]]))
}

console.log(extractAttributes('<span class="red"></span>'))

Your browser information:

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

Challenge Information:

Daily Coding Challenge - HTML Attribute Extractor
https://www.freecodecamp.org/learn/daily-coding-challenge/2025-10-19

I’ve edited your post to improve the readability of the code. When you enter a code block into a forum post, please precede it with three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add the backticks.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

you are right, it looks like our console does not support that. You can use the browser console tho, that one will show the plain string

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.