From 12b2efa2cc1e64ce02ef654d21ddf86d78b10355 Mon Sep 17 00:00:00 2001 From: Alexandre BIEDIGER Date: Thu, 17 Feb 2022 17:53:45 +0800 Subject: [PATCH] Update bad-function.js --- bad-function.js | 31 ++++++++++--------------------- 1 file changed, 10 insertions(+), 21 deletions(-) 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; }