Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bad-function.js #9

Open
wants to merge 1 commit into
base: functions-07-small-do-one-thing
Choose a base branch
from
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;
}