From d176ca4020150db898380ec7fdac969cde593560 Mon Sep 17 00:00:00 2001 From: Neil Gorski Date: Wed, 16 Apr 2025 00:40:36 +0200 Subject: [PATCH] done --- 01/app.js | 9 +++++++- 02/app.js | 13 ++++++++++- 03/app.js | 37 ++++++++++++++++++++---------- 04/app.js | 23 +++++++++++++++---- 05/app.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 129 insertions(+), 21 deletions(-) diff --git a/01/app.js b/01/app.js index 1c9992ed..81c11440 100644 --- a/01/app.js +++ b/01/app.js @@ -1 +1,8 @@ -console.log('DOM'); \ No newline at end of file +console.log("DOM"); +const elCommentsItem = document.querySelector( + ".comments__item.comments__item--newest" +); +if (elCommentsItem) { + const dataInfoElements = elCommentsItem.querySelectorAll("[data-info]"); + console.log(`There are ${dataInfoElements.length} emelents.`); +} diff --git a/02/app.js b/02/app.js index 1c9992ed..e24dae0e 100644 --- a/02/app.js +++ b/02/app.js @@ -1 +1,12 @@ -console.log('DOM'); \ No newline at end of file +console.log("DOM"); + +const dataUrlList = document.querySelectorAll("a"); +if (dataUrlList) { + const dataUrlArr = Array.from(dataUrlList); + dataUrlArr.forEach((el) => { + if (el.dataset.url) { + const url = el.dataset.url; + el.setAttribute("href", url); + } + }); +} diff --git a/03/app.js b/03/app.js index c299ca32..758f1be2 100644 --- a/03/app.js +++ b/03/app.js @@ -1,14 +1,27 @@ -console.log('DOM'); +console.log("DOM"); const buttonSettings = { - attr: { - className: 'btn', - title: 'super button' - }, - css: { - border: '1px solid #336699', - padding: '5px 20px', - color: '#444' - }, - text: 'Click me!', -} \ No newline at end of file + attr: { + className: "btn", + title: "super button", + }, + css: { + border: "1px solid #336699", + padding: "5px 20px", + color: "#444", + }, + text: "Click me!", +}; + +const parentSectionBtn = document.querySelector(".parent-for-button"); +const button = document.createElement("button"); + +for (key in buttonSettings.attr) { + button.setAttribute(key, buttonSettings.attr[key]); +} +for (key in buttonSettings.css) { + button.style[key] = buttonSettings.css[key]; +} +button.innerText = buttonSettings.text; + +parentSectionBtn.appendChild(button); diff --git a/04/app.js b/04/app.js index e6411e4e..561d9c6c 100644 --- a/04/app.js +++ b/04/app.js @@ -1,8 +1,21 @@ -console.log('DOM'); +console.log("DOM"); // struktura do wykorzystania w pętli const menuItems = [ - {text: 'start', url: '/'}, - {text: 'galeria', url: '/gallery'}, - {text: 'kontakt', url: '/contact'}, -]; \ No newline at end of file + { text: "start", url: "/" }, + { text: "galeria", url: "/gallery" }, + { text: "kontakt", url: "/contact" }, +]; + +const navSection = document.querySelector("nav"); +const unorderdList = document.createElement("ul"); +navSection.appendChild(unorderdList); + +for (let i = 0; i < menuItems.length; i++) { + const listItem = document.createElement("li"); + const ancherTag = document.createElement("a"); + listItem.appendChild(ancherTag); + ancherTag.href = menuItems[i].url; + ancherTag.innerText = menuItems[i].text; + unorderdList.appendChild(listItem); +} diff --git a/05/app.js b/05/app.js index 39abe5d5..18b1c065 100644 --- a/05/app.js +++ b/05/app.js @@ -1,3 +1,67 @@ -console.log('DOM'); +console.log("DOM"); -const curr = document.querySelector('.js-curr'); +const curr = document.querySelector(".js-curr"); +// 1. +const deletBtn = document.createElement("button"); +deletBtn.innerText = "usuń z koszyka"; +curr.parentElement.appendChild(deletBtn); +// 2. +const childArr = [...curr.parentElement.children]; +childArr.forEach((element) => { + if (element) { + element.classList.add("siblings"); + } +}); +// 3. +curr.parentElement.nextElementSibling.setAttribute( + "title", + "nextElementSibling" +); +// 4. +const lastArticle = curr.parentElement.parentElement.lastElementChild; +console.log(lastArticle); +const lastArticleBtn = lastArticle.querySelector("button"); +const newP = document.createElement("p"); +newP.innerText = "---> New text was added with JavaScript right here <---"; +lastArticle.insertBefore(newP, lastArticleBtn); + +// 5. + +const articleData = { + article: { + element: "article", + classList: ["articles__item", "article"], + text: "", + }, + header: { + element: "h1", + classList: ["article__title"], + text: "JS - Fist Article", + }, + paragrph: { + element: "p", + classList: ["article__description"], + text: "JS - Lorem ipsum dolor sit amet consectetur adipisicing elit. Consequatur quo quibusdam, nemo neque consequuntur pariatur totam? Facere quaerat molestias hic.", + }, + button: { + element: "button", + classList: ["article__btn"], + text: "JS - Kupuję!", + }, +}; + +const sectionArticles = curr.parentElement.parentElement; +const newArticle = createElement(articleData.article); +sectionArticles.insertBefore(newArticle, sectionArticles.firstChild); +newArticle.appendChild(createElement(articleData.header)); +newArticle.appendChild(createElement(articleData.paragrph)); +newArticle.appendChild(createElement(articleData.button)); + +function createElement(obj) { + const element = document.createElement(obj.element); + for (classElement in obj.classList) { + element.classList.add(classElement); + } + element.innerText = obj.text; + return element; +}