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
48 changes: 47 additions & 1 deletion src/scripts/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,49 @@
'use strict';

// write your code here
const promise1 = new Promise((resolve, reject) => {
const logo = document.querySelector('.logo');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

document.querySelector('.logo') is used and then addEventListener is called immediately. If .logo does not exist the code will throw. Guard the lookup: e.g. const logo = document.querySelector('.logo'); if (logo) { logo.addEventListener(...) } so tests/environments without the element don't fail.


if (logo) {
logo.addEventListener('click', () => {
resolve();
});
}
});

promise1.then(() => {
const success = document.createElement('div');

success.classList.add('message');
success.textContent = 'Promise was resolved!';
document.body.appendChild(success);
});

promise1.catch(() => {
const error = document.createElement('div');

error.classList.add('message', 'error-message');
error.textContent = 'Promise was rejected!';
document.body.appendChild(error);
});

const promise2 = new Promise((resolve, reject) => {
setTimeout(() => {
reject(new Error('error'));
}, 3000);
});

promise2.then(() => {
const success = document.createElement('div');

success.classList.add('message');
success.textContent = 'Promise was resolved!';
document.body.appendChild(success);
});

promise2.catch(() => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The description requires success handlers for both promises. promise2 currently only has a catch. Add promise2.then(() => { /* append <div class="message">Promise was resolved!</div> to body */ }) so promise2 has both success and error handlers.

const error = document.createElement('div');

error.classList.add('message', 'error-message');
error.textContent = 'Promise was rejected!';
document.body.appendChild(error);
});