const flowers = [
{
author: "Белі Свім",
name: "Троянда",
price: 60
},
{
author: "Джеймс Лоррі",
name: "Тюльпан"
},
{
name: "Нарцис",
price: 45
}
]
let div = document.createElement('div');
div.id = 'root';
document.body.append(div);
function flowersList(arr) {
let ul = document.createElement('ul');
arr.forEach(elems => {
let li = document.createElement('li');
li.textContent = `author: ${elems.author}; name: ${elems.name}; price: ${elems.price}`;
try {
//debugger;
if (elems.author && elems.name && elems.price) {
ul.append(li);
} else {
throw new Error();
}
} catch (e) {
console.log(e);
//console.log('work catch');
}
});
return ul;
}
let flowersUl = flowersList(flowers);
document.getElementById('root').append(flowersUl);
const flowers = [
{
author: "Белі Свім",
name: "Троянда",
price: 60
},
{
author: "Джеймс Лоррі",
name: "Тюльпан"
},
{
name: "Нарцис",
price: 45
}
]
let div = document.createElement('div');
div.id = 'root';
document.body.append(div);
function flowersList(arr) {
let ul = document.createElement('ul');
arr.forEach(elems => {
let li = document.createElement('li');
li.textContent = `author: ${elems.author}; name: ${elems.name}; price: ${elems.price}`;
try {
//debugger;
if (elems.author && elems.name && elems.price) {
ul.append(li);
} else {
throw new Error('Выдало ошибку');
}
} catch (e) {
console.error(`${e} Проверьте ваши данные`);
//console.log('work catch');
}
});
return ul;
}
let flowersUl = flowersList(flowers);
document.getElementById('root').append(flowersUl);