Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb708737

Browse files
committed
Updated the code with comments and explainations of what is going on within the document.
1 parent9687f27 commitb708737

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

‎boxes/boxes.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Array of assorted colors
12
constcolors=['#FF6633','#FFB399','#FF33FF','#FFFF99','#00B3E6',
23
'#E6B333','#3366E6','#999966','#99FF99','#B34D4D',
34
'#80B300','#809900','#E6B3B3','#6680B3','#66991A',
@@ -10,12 +11,15 @@ const colors = ['#FF6633', '#FFB399', '#FF33FF', '#FFFF99', '#00B3E6',
1011
'#E64D66','#4DB380','#FF4D4D','#99E6E6','#6666FF'
1112
];
1213

14+
//Selections of the main div, h1, and links on the page for DOM manipulation.
1315
constdiv=document.querySelector(".boxes")
1416
consth1=document.querySelector("h1")
1517
constlinks=document.querySelectorAll('a')
1618

19+
// Function that creates a set number of boxes displayed on the page
1720
functioncreateBoxes(number){
1821
letcolorIndex=0;
22+
// Loops through a set number of times, creates new boxes, assigns color from the array, and pushes it to the main div.
1923
for(leti=0;i<number;i++){
2024
letbox=document.createElement('div');
2125
box.style=`background-color:${colors[colorIndex]} `
@@ -26,13 +30,17 @@ function createBoxes(number) {
2630
colorIndex=0;
2731
}else{colorIndex++}
2832
}
33+
34+
//Puts an Event Listener on the main div that removes the target (child) element and updates the amount of boxes on the page.
2935
div.addEventListener('click',function(e){
3036
e.target.remove();
3137
h1.textContent=`There are${div.querySelectorAll('.box').length} boxes on the page`;
3238
});
3339
}
3440

3541
for(leti=0;i<links.length;i++){
42+
/* Loops through all of the links on the page and adds an Event Listener on them to put a set amount of boxes on the page and
43+
update the amount of boxes on the page */
3644
links[i].addEventListener('click',function(){
3745
div.innerHTML=''
3846
createBoxes(Number(links[i].textContent))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp