-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·89 lines (77 loc) · 2.82 KB
/
script.js
File metadata and controls
executable file
·89 lines (77 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Challenge: Add a new element
* - In JavaScript, create a new element to hold a navigation menu
* - Add an unordered list and a series of no less than five links to the list
* - Use single words like “home”, “about”, etc for the list items and set the src attribute to # for simplicity
* - Add the new navigation element to the DOM directly after the header
* - Write basic CSS and add classes as necessary to create a horizontal layout for the menu.
* - A tip: Use either display flex or display grid to create the horizontal menu.
*/
// Import Backpack class from the module (assuming Backpack.js exists and is properly defined)
import Backpack from "./Backpack.js";
const everydayPack = new Backpack(
"Everyday Backpack",
30,
"grey",
15,
26,
26,
false,
"December 5, 2018 15:00:00 PST",
"../assets/images/everyday.svg"
);
const content = `
<figure class="backpack__image">
<img src=${everydayPack.image} alt="" />
</figure>
<h1 class="backpack__name">Everyday Backpack</h1>
<ul class="backpack__features">
<li class="packprop backpack__volume">Volume:<span> ${
everydayPack.volume
}l</span></li>
<li class="packprop backpack__color">Color:<span> ${
everydayPack.color
}</span></li>
<li class="backpack__age">Age:<span> ${everydayPack.backpackAge()} days old</span></li>
<li class="packprop backpack__pockets">Number of pockets:<span> ${
everydayPack.pocketNum
}</span></li>
<li class="packprop backpack__strap">Left strap length:<span> ${
everydayPack.strapLength.left
} inches</span></li>
<li class="packprop backpack__strap">Right strap length:<span> ${
everydayPack.strapLength.right
} inches</span></li>
<li class="packprop backpack__lid">Lid status:<span> ${
everydayPack.lidOpen
}</span></li>
</ul>
`;
const main = document.querySelector(".maincontent");
const newArticle = document.createElement("article");
newArticle.classList.add("backpack");
newArticle.setAttribute("id", "everyday");
newArticle.innerHTML = content;
main.append(newArticle);
// Creating a new navigation element
const nav = document.createElement("nav");
nav.classList.add("navigation");
// Creating an unordered list for the navigation menu
const ul = document.createElement("ul");
ul.classList.add("nav-list");
// Array of link names
const links = ["Home", "About", "Services", "Contact", "Blog"];
// Creating list items and links
links.forEach((linkText) => {
const li = document.createElement("li");
li.classList.add("nav-item");
const a = document.createElement("a");
a.setAttribute("href", "#");
a.textContent = linkText;
li.appendChild(a);
ul.appendChild(li);
});
nav.appendChild(ul);
// Insert the navigation menu directly after the header
const header = document.querySelector("header");
header.insertAdjacentElement("afterend", nav);