-
Notifications
You must be signed in to change notification settings - Fork 1.7k
add task solution #1741
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
base: master
Are you sure you want to change the base?
add task solution #1741
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,32 @@ | |
|
|
||
| const pushNotification = (posTop, posRight, title, description, type) => { | ||
| // write code here | ||
| const container = document.createElement('div'); | ||
|
|
||
| if (container) { | ||
| container.className = `notification notification ${type}`; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The class |
||
| } | ||
|
|
||
| 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( | ||
|
|
||
There was a problem hiding this comment.
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.createElementwill 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 likenull.