Skip to content
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

pull request #77

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
38 changes: 37 additions & 1 deletion 07_04/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,46 @@
* Challenge: Build and modify an array
* - Build an array with 8 items
* - Remove the last item
* - Add the last item as the first item on the array
* - Add the last item as the first item on the array
* - Sort the items by alphabetical order
* - Use the find() method to find a specific item in the array
* - Remove the item you found using the find method from the array.
*/

Choose a reason for hiding this comment

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

// Step 1: Build an array with 8 items
let items = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew"];
console.log("Initial array:", items);

// Step 2: Remove the last item
let lastItem = items.pop();
console.log("Array after removing last item:", items);
console.log("Last item:", lastItem);

// Step 3: Add the last item as the first item on the array
items.unshift(lastItem);
console.log("Array after adding last item to the start:", items);

// Step 4: Sort the items by alphabetical order
items.sort();
console.log("Array sorted alphabetically:", items);

// Step 5: Use the find() method to find a specific item in the array
let itemToFind = "cherry";
let foundItem = items.find(item => item === itemToFind);
console.log("Found item:", foundItem);

// Step 6: Remove the item you found using the find() method from the array
if (foundItem) {
items = items.filter(item => item !== foundItem);
console.log(Array after removing ${foundItem}:, items);
} else {
console.log(${itemToFind} not found in the array.);
}

// - Build an array with 8 items
let items = [
"apple",
"banana",
"cherry",
"date",
"elderberry",
"fig",
"grape",
"honeydew",
];

console.log("Original Array:", items);

// - Remove the last item
let lastItem = items.pop();
console.log("After removing the last item:", items);

// - Add the last item as the first item on the array
items.unshift(lastItem);
console.log("After adding the last item as the first item:", items);

// - Sort the items by alphabetical order
items.sort();
console.log("After sorting alphabetically:", items);

// - Use the find() method to find a specific item in the array
let itemToFind = "date";
let foundItem = items.find((item) => item === itemToFind);
console.log(`Found item: ${foundItem}`);

// - Remove the item you found using the find method from the array
let index = items.indexOf(foundItem);
if (index !== -1) {
items.splice(index, 1);
}
console.log("After removing the found item:", items);
78 changes: 47 additions & 31 deletions 08_16/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,69 @@
*/
import Backpack from "./components/Backpack.js";

const everydayPack = new Backpack(
"pack01",
"Everyday Backpack",
30,
"grey",
15,
26,
26,
false,
"December 5, 2018 15:00:00 PST",
"../assets/images/everyday.svg"
);
const backpackObjectArray = [
new Backpack(
"pack01",
"Everyday Backpack",
30,
"grey",
15,
26,
26,
false,
"December 5, 2018 15:00:00 PST",
"../assets/images/everyday.svg"
),
new Backpack(
"pack02",
"Hiking Backpack",
50,
"blue",
20,
30,
30,
true,
"January 1, 2020 10:00:00 PST",
"../assets/images/hiking.svg"
),
// Daha fazla sırt çantası nesnesi ekleyin
];

const content = `
const main = document.querySelector(".maincontent");

backpackObjectArray.forEach((backpack) => {
const content = `
<figure class="backpack__image">
<img src=${everydayPack.image} alt="" />
<img src=${backpack.image} alt="${backpack.name}" />
</figure>
<h1 class="backpack__name">${everydayPack.name}</h1>
<h1 class="backpack__name">${backpack.name}</h1>
<ul class="backpack__features">
<li class="packprop backpack__volume">Volume:<span> ${
everydayPack.volume
backpack.volume
}l</span></li>
<li class="packprop backpack__color">Color:<span> ${
everydayPack.color
backpack.color
}</span></li>
<li class="backpack__age">Age:<span> ${everydayPack.backpackAge()} days old</span></li>
<li class="backpack__age">Age:<span> ${backpack.backpackAge()} days old</span></li>
<li class="packprop backpack__pockets">Number of pockets:<span> ${
everydayPack.pocketNum
backpack.pocketNum
}</span></li>
<li class="packprop backpack__strap">Left strap length:<span> ${
everydayPack.strapLength.left
backpack.strapLength.left
} inches</span></li>
<li class="packprop backpack__strap">Right strap length:<span> ${
everydayPack.strapLength.right
backpack.strapLength.right
} inches</span></li>
<li class="feature backpack__lid">Lid status:<span> ${
everydayPack.lidOpen ? "open" : "closed"
backpack.lidOpen ? "open" : "closed"
}</span></li>
</ul>

`;

const main = document.querySelector(".maincontent");
`;

const newArticle = document.createElement("article");
newArticle.classList.add("backpack");
newArticle.setAttribute("id", "everyday");
newArticle.innerHTML = content;
const newArticle = document.createElement("article");
newArticle.classList.add("backpack");
newArticle.setAttribute("id", backpack.id);
newArticle.innerHTML = content;

main.append(newArticle);
main.append(newArticle);
});
39 changes: 39 additions & 0 deletions Practice/08_06/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,42 @@
* - Main function creates article element with data from object
* - Helper function creates.
*/

// Object with data
const articleData = {
title: "JavaScript Practice",
content: "This is a practice exercise to pass values between functions.",
author: "Serhat Ece",
date: "2024-07-27",
};

// Main function to create the article element
function createArticle(data) {
// Create article element
const article = document.createElement("article");

// Use helper functions to create and append elements
const title = createElement("h1", data.title);
const content = createElement("p", data.content);
const author = createElement("p", `Author: ${data.author}`);
const date = createElement("p", `Date: ${data.date}`);

// Append elements to the article
article.appendChild(title);
article.appendChild(content);
article.appendChild(author);
article.appendChild(date);

// Append the article to the body or any other container
document.body.appendChild(article);
}

// Helper function to create an element with text content
function createElement(tag, text) {
const element = document.createElement(tag);
element.textContent = text;
return element;
}

// Call the main function with article data
createArticle(articleData);