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

dom exercises submission by Yifei Sun #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
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
35 changes: 27 additions & 8 deletions exercises/part1-selectors-and-events/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,32 @@ Part 1: Set the variable below equal to the paragraph element representing the
first test result.
==================== */

let firstResult;
let firstResult= document.getElementById("result-1");

/* ====================
Parts 2: Set the variable below equal to a collection of the paragraph
elements representing the 2nd and 3rd results.
==================== */

let secondAndThirdResults;
let secondAndThirdResults=document.getElementsByClassName("result result-2-3");

/* ====================
Parts 3: Set the variable below equal to a collection of the paragraph
elements representing the all of the results.
==================== */

let allResults;
let allResults=document.querySelectorAll(".result");

/* ====================
Part 4: Add an event listener to the button in problem 4 that changes the
button's own text to "I'm Clicked!"
==================== */

let imClickedButton;
let imClickedButton=document.getElementById("im-clicked-button");
if (imClickedButton) {
imClickedButton.addEventListener('click', () => {});
imClickedButton.addEventListener('click', () => {
imClickedButton.textContent="I'm Clicked!";
});
}

/* ====================
Expand All @@ -55,12 +57,23 @@ HINT: You may need some global state for this problem.

let spanContainer = document.querySelector('#span-container');
spanContainer.appendChild(htmlToElement('<span>0</span>'));

let addSpanButton;
let addSpanButton=document.getElementById("add-span-button");
let n=0;
if (addSpanButton) {
addSpanButton.addEventListener('click', () => {});
addSpanButton.addEventListener('click', () => {
n=n+1;

spanContainer.appendChild(htmlToElement("<span>"+ n+ "</span>"));
});
}



window.secondAndThirdResults=secondAndThirdResults;
window.allResults=allResults;
window.imClickedButton=imClickedButton;
window.spanContainer=spanContainer;

/* =====================

Results (all should report success)
Expand Down Expand Up @@ -120,3 +133,9 @@ function checkResults() {
}

checkResults();

window.firstResult= firstResult;
window.secondAndThirdResults=secondAndThirdResults;
window.allResults=allResults;
window.imClickedButton=imClickedButton;
window.spanContainer=spanContainer;