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
26 changes: 26 additions & 0 deletions src/scripts/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,32 @@

const pushNotification = (posTop, posRight, title, description, type) => {
// write code here
const container = document.createElement('div');

if (container) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check is not necessary. document.createElement will always return an element. In the rare case that it fails (e.g., out of memory), it will throw an error rather than returning a falsy value like null.

container.className = `notification notification ${type}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class notification is being assigned twice here. While this works in the browser, it's redundant. You can simplify this to container.className = notification ${type};. An even more robust way to handle classes is using the classList property, like container.classList.add('notification', type);.

}

container.style.top = posTop + 'px';
container.style.right = posRight + 'px';

const titleEl = document.createElement('h2');

titleEl.className = `title`;
titleEl.textContent = title;

const descriptionEl = document.createElement('p');

descriptionEl.className = 'description';
descriptionEl.textContent = description;

container.append(titleEl, descriptionEl);

document.body.append(container);

setTimeout(() => {
container.style.display = 'none';
}, 2000);
};

pushNotification(
Expand Down