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

// write your code here
const logo = document.querySelector('.logo');

Choose a reason for hiding this comment

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

You query .logo into logo, but later code uses logo.before(...). If .logo is missing this will cause runtime errors. Consider appending to document.body in handlers or handle the logo === null case here so handlers don't rely on logo being non-null.


const promise1 = new Promise((resolve, reject) => {
if (logo) {
logo.addEventListener('click', () => {
resolve();
});
} else {
reject(new Error('no data'));
}
});

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

const resolved = () => {
const div = document.createElement('div');

div.className = 'message';
div.textContent = 'Promise was resolved!';
document.body.append(div);
};

const rejected = () => {
const div = document.createElement('div');

div.className = 'message error-message';
div.textContent = 'Promise was rejected!';
document.body.append(div);
};

promise1.then(resolved).catch(rejected);
promise2.then(resolved).catch(rejected);