diff --git a/bad-function.js b/bad-function.js index 7074023..884c621 100644 --- a/bad-function.js +++ b/bad-function.js @@ -1,26 +1,15 @@ -function renderContent(renderInformation) { - const element = renderInformation.element; - if (element === 'script' || element === 'SCRIPT') { +function renderContent({element, attributes, content, root}) { + if (element.toLowerCase() === 'script') { throw new Error('Invalid element.'); } - - let partialOpeningTag = '<' + element; - - const attributes = renderInformation.attributes; - - for (const attribute of attributes) { - partialOpeningTag = - partialOpeningTag + ' ' + attribute.name + '="' + attribute.value + '"'; + + let attributesStr = ''; + for (const {name, value} of attributes) { + attributesStr += ` ${name}="${value}"`; } - const openingTag = partialOpeningTag + '>'; - - const closingTag = ''; - const content = renderInformation.content; - - const template = openingTag + content + closingTag; - - const rootElement = renderInformation.root; - - rootElement.innerHTML = template; + const openingTag = `<${element} ${attributesStr}>`; + const closingTag = ``; + + root.innerHTML = openingTag + content + closingTag; }