Tell us what’s happening:
Hi I’m stuck on activating and updating the ROM any explanations would be useful.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
// 1. You must define a variable that points to your results list <ul> element.
// (Assuming your HTML has <ul id="results-list">)
const resultsList = document.getElementById('results-list');
/**
* Correct function to update the DOM by adding a new <li> element.
* @param {string} resultText - The formatted conversion string to display.
*/
function updateResultsList(resultText) {
// Safety check: ensure the results list element exists
if (!resultsList || !resultText) {
return;
}
// 1. CREATE: Create the new <li> element
const listItem = document.createElement('li');
// 2. SET CONTENT: Set the text content of the new element
listItem.textContent = resultText;
// 3. APPEND: Add the new element to the existing <ul> in the DOM
resultsList.appendChild(listItem);
// The successful execution of resultsList.appendChild(listItem)
// is what satisfies the DOM update test.
}
// ... your existing code where you call the function ...
// The full button listener structure should look something like this:
/*
if (convertButton) {
convertButton.addEventListener('click', (event) => {
event.preventDefault();
// ... conversion logic to calculate updateResult ...
// This is where you call the function:
updateResultsList(updateResultsList);
});
}
*/
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36
Challenge Information:
Build a Recipe Ingredient Converter - Step 18