-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Arrays, Objects and DOM sections update
- Loading branch information
Showing
5 changed files
with
245 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,101 @@ | ||
// 23th Exercise | ||
|
||
const duplicateSubmit = document.querySelector("#duplicate-submit-23") | ||
|
||
duplicateSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const array = document.querySelector("#array-23").value.split(" ") | ||
const duplicate = document.querySelector("#duplicate-23") | ||
|
||
let duplicateArray = [] | ||
array.forEach(element => { | ||
if(!duplicateArray.includes(element)) | ||
duplicateArray.push(element) | ||
}) | ||
|
||
duplicate.textContent = `The array without duplicated elements is [${duplicateArray.join(", ")}]` | ||
}) | ||
|
||
// 24th Exercise | ||
|
||
const concatenateSubmit = document.querySelector("#concatenate-submit-24") | ||
|
||
concatenateSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const array1 = document.querySelector("#array-1-24").value.split(" ") | ||
const array2 = document.querySelector("#array-2-24").value.split(" ") | ||
const concatenate = document.querySelector("#concatenate-24") | ||
|
||
const concatenateArray = [...array1, ...array2] | ||
|
||
concatenate.textContent = `The concatenation of both arrays is [${concatenateArray.join(", ")}]` | ||
}) | ||
|
||
// 25th Exercise | ||
|
||
const intersectionSubmit = document.querySelector("#intersection-submit-25") | ||
|
||
intersectionSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const array1 = document.querySelector("#array-1-25").value.split(" ") | ||
const array2 = document.querySelector("#array-2-25").value.split(" ") | ||
const intersection = document.querySelector("#intersection-25") | ||
|
||
const intersectionArray = array1.filter(element => array2.includes(element)) | ||
|
||
let duplicateArray = [] | ||
intersection.forEach(element => { | ||
if(!duplicateArray.includes(element)) | ||
duplicateArray.push(element) | ||
}) | ||
|
||
intersection.textContent = `The intersection of both arrays is [${duplicateArray.join(", ")}]` | ||
}) | ||
|
||
// 26th Exercise | ||
|
||
const meanSubmit = document.querySelector("#mean-submit-26") | ||
|
||
meanSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const array = document.querySelector("#array-26").value.split(" ") | ||
const mean = document.querySelector("#mean-26") | ||
|
||
const meanArray = array.reduce((acc, element) => Number(element) + acc, 0) | ||
|
||
mean.textContent = `The mean of the elements in the array is ${(meanArray / array.length).toFixed(2)}` | ||
}) | ||
|
||
// 27th Exercise | ||
|
||
const sumSubmit = document.querySelector("#sum-submit-27") | ||
|
||
sumSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const sum = document.querySelector("#sum-27") | ||
}) | ||
|
||
// 28th Exercise | ||
|
||
const filterSubmit = document.querySelector("#filter-submit-28") | ||
|
||
filterSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const filter = document.querySelector("#filter-28") | ||
}) | ||
|
||
// 29th Exercise | ||
|
||
const uniteSubmit = document.querySelector("#unite-submit-29") | ||
|
||
uniteSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const unite = document.querySelector("#unite-29") | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,83 @@ | ||
// 30th Exercise | ||
|
||
const contentSubmit = document.querySelector("#content-submit-30") | ||
|
||
contentSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
const title = document.querySelector("#title-30").value | ||
const h1element = document.querySelector("#title-h1-30") | ||
|
||
h1element.textContent = title | ||
}) | ||
|
||
// 31th Exercise | ||
|
||
const colorSubmit = document.querySelector("#color-submit-31") | ||
|
||
colorSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
console.log("object"); | ||
|
||
const newColor = document.querySelector("#color-31").value | ||
const list = document.querySelector("#paragraph-31") | ||
|
||
list.style.color = newColor | ||
}) | ||
|
||
// 32th Exercise | ||
|
||
const classSubmit = document.querySelector("#class-submit-32") | ||
|
||
classSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
}) | ||
|
||
// 33th Exercise | ||
|
||
const addingSubmit = document.querySelector("#adding-submit-33") | ||
|
||
addingSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
|
||
// 34th Exercise | ||
const element = document.querySelector("#element-33").value | ||
const list = document.querySelector("#list-33") | ||
|
||
const newElement = document.createElement("li") | ||
newElement.textContent = element | ||
|
||
list.appendChild(newElement) | ||
}) | ||
|
||
// 35th Exercise | ||
// // 34th Exercise | ||
|
||
// .addEventListener("click", (e) => { | ||
// e.preventDefault() | ||
// }) | ||
|
||
// 35th Exercise | ||
|
||
// 36th Exercise | ||
const filterSubmit = document.querySelector("#filter-submit-35") | ||
|
||
filterSubmit.addEventListener("click", (e) => { | ||
e.preventDefault() | ||
}) | ||
|
||
// // 36th Exercise | ||
|
||
// 37th Exercise | ||
// .addEventListener("click", (e) => { | ||
// e.preventDefault() | ||
// }) | ||
|
||
// // 37th Exercise | ||
|
||
// .addEventListener("click", (e) => { | ||
// e.preventDefault() | ||
// }) | ||
|
||
// 38th Exercise | ||
// // 38th Exercise | ||
|
||
// .addEventListener("click", (e) => { | ||
// e.preventDefault() | ||
// }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters