/* file: script.js */
let storyContainer = document.querySelector(".story-container");
const scaryStoryBtn = document.getElementById("scary-btn");
const funnyStoryBtn = document.getElementById("funny-btn");
const adventureStoryBtn = document.getElementById("adventure-btn");
const resultParagraph = document.getElementById("result");
const storyObj = {
scary: {
story: `In the dark woods, a group of friends stumbled upon an old, abandoned cabin. They enter the cabin and awaken something malevolent that had been dormant for centuries.`,
borderColor: "#ee4b2b",
},
funny: {
story: `During a camping trip, Mark decided to show off his culinary skills by cooking dinner over an open fire. However, his attempt caused him to burn the dinner as well as his eyebrows off.`,
borderColor: "#f1be32",
},
adventure: {
story: `Lost in the heart of the Amazon rain forest, Sarah and Jake stumbled upon an ancient temple. They braved deadly traps and encountered strange wildlife, all while deciphering cryptic clues left behind by a mysterious civilization.`,
borderColor: "#acd157"
},
};
// User Editable Region
function displayStory(genre) {
const result = document.getElementById("result");
if (storyObj.hasOwnProperty(genre)) {
result.textContent = storyObj[genre].story;
storyContainer.style.borderColor = storyObj[genre].borderColor;
} else {
result.textContent = "Sorry, that genre is not available.";
storyContainer.style.borderColor = "#000"; // default or error color
}
}
// User Editable Region
scaryStoryBtn.addEventListener("click", displayStory);
/* file: script.js */
let storyContainer = document.querySelector(".story-container");
const scaryStoryBtn = document.getElementById("scary-btn");
const funnyStoryBtn = document.getElementById("funny-btn");
const adventureStoryBtn = document.getElementById("adventure-btn");
const resultParagraph = document.getElementById("result");
const storyObj = {
scary: {
story: `In the dark woods, a group of friends stumbled upon an old, abandoned cabin. They enter the cabin and awaken something malevolent that had been dormant for centuries.`,
borderColor: "#ee4b2b",
},
funny: {
story: `During a camping trip, Mark decided to show off his culinary skills by cooking dinner over an open fire. However, his attempt caused him to burn the dinner as well as his eyebrows off.`,
borderColor: "#f1be32",
},
adventure: {
story: `Lost in the heart of the Amazon rain forest, Sarah and Jake stumbled upon an ancient temple. They braved deadly traps and encountered strange wildlife, all while deciphering cryptic clues left behind by a mysterious civilization.`,
borderColor: "#acd157"
},
};
// User Editable Region
let result = document.querySelector("#result");
function displayStory(genre) {
if(storyObj[genre]) {
result.textContent = storyObj[genre].story;
result.style.borderColor = storyObj[genre].borderColor;
}
}
displayStory("scary");
// User Editable Region
scaryStoryBtn.addEventListener("click", displayStory);
Please describe what’s happening,
if you need help with a test, what the test is?
Is there any error or feedback
Can you show the part of your code which fulfills the test requirement?
What have you tried to troubleshoot?