Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 10 additions & 21 deletions bad-function.js
Original file line number Diff line number Diff line change
@@ -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 = '</' + element + '>';
const content = renderInformation.content;

const template = openingTag + content + closingTag;

const rootElement = renderInformation.root;

rootElement.innerHTML = template;
const openingTag = `<${element} ${attributesStr}>`;
const closingTag = `</${element}>`;

root.innerHTML = openingTag + content + closingTag;
}