Second attempt at getting support help. Changed code completely from first attempt, and after 5 hours of scouring for help/answers I can’t get requirements 6, 9, and 12 to trigger successfully.
Your code so far
<!-- file: index.html -->
<div id="flashcard">
<div id="front"></div>
<div id="back"></div>
</div>
<h2>Manage Cards</h2>
<button id="delete-btn">Delete</button>
<h3>All Cards</h3>
<!-- List all cards from currentCards -->
<h3>Add New Card</h3>
<!-- Add new card to currentCards from HTML form submit -->
<form id="entry-form">
<textarea id="front-text" name="front" required></textarea>
<textarea id="back-text" name="back" required></textarea>
<button type="submit">Add Card</button>
</form>
/* file: index.ts */
interface FlashCard {
questionText: string;
questionAnswer: string;
}
let currentCards: FlashCard[] = [
{
questionText: "Biggest city in America",
questionAnswer: "New York"
},
{
questionText: "Tallest skyscraper in the world",
questionAnswer: "Burj Khalifa"
}
];
const flashcard = document.getElementById("flashcard")!;
const front = document.getElementById("front")!;
const back = document.getElementById("back")!;
const deleteBtn = document.getElementById("delete-btn")!;
const form = document.getElementById("entry-form") as HTMLFormElement;
const frontText = document.getElementById("front-text") as HTMLTextAreaElement;
const backText = document.getElementById("back-text") as HTMLTextAreaElement;
class InvalidUserInputError extends Error {
constructor(message: string) {
super(message);
this.name = "InvalidUserInputError";
}
}
function displayCard() {
if (currentCards.length === 0) {
front.textContent = "";
back.textContent = "";
return;
}
const card = currentCards[currentCards.length - 1];
front.textContent = card.questionText;
back.textContent = card.questionAnswer;
}
displayCard();
flashcard.addEventListener("click", () => {
flashcard.classList.add("flipped");
});
deleteBtn.addEventListener("click", () => {
currentCards.pop();
flashcard.classList.remove("flipped");
displayCard();
});
form.addEventListener("submit", (e) => {
e.preventDefault();
const question = frontText.value.trim();
const answer = backText.value.trim();
if (!question || !answer) {
throw new InvalidUserInputError(
"Question and answer cannot be empty."
);
}
currentCards.push({
questionText: question,
questionAnswer: answer
});
flashcard.classList.remove("flipped");
displayCard();
frontText.value = "";
backText.value = "";
});
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/150.0.0.0 Safari/537.36
Challenge Information:
Build a Flashcard Quiz App - Build a Flashcard Quiz App
Hi, thanks. I went through my code and applied your suggestion to relink the index.ts file in my HTML (I originally had it in there but still failed the tests) and changed classlist.add to classlist.toggle which allowed checks 6 and 12 in the test to succeed. Still failed on 9, but realised it was because I had not comleted the add new card portion of the test (Which doesn’t immediately make sense, but overall does when I think back on it).
Thank you so much for your help and in pointing me to a direction which ended up solving this problem.