Build a Recipe Ingredient Converter - Step 18

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

Hello there!

Your code is kinda right, but you should look at your task one more time.

It says:

”””
For example, if the input is flour, 5, and gram, the result should be:

Example Code
flour: 0.02 cup
flour: 0.18 ounce
flour: 1.00 teaspoon

“““

You should append new elements in this format.
There’s another problem – you’re checking one element. You should check all the elements from the units array.

Happy coding! Try doing that task from the scratch, reading carefully through your task.