public/assets/js/index.js
// displays all the berders in the db
displays all the berders in the db
displays all the berders in the db
async function displayburgers(){
    try{
        let allTheburgersHtml = "";
        let allTheDevouredHambersHtml = "";
        const {data: allburgers} = await axios.get("/api/burger")
        for(let i=0; i < allburgers.length; i++){
            const {id, burger_name: burgerName, devoured} = allburgers[i]
            if(devoured){
                const devouredburgerHtml = `
                    <div class="burger ${id}">
                        ${id}: ${burgerName}
                    </div>`
                allTheDevouredHambersHtml += devouredburgerHtml;            
            }else{
                const devouredburgerHtml = `
                    <div class="burger ${id}">
                        ${id}: ${burgerName}
                        <button id=${id} class="devour-btn">Devour!</button>
                    </div>`
                allTheburgersHtml += devouredburgerHtml;
            }
        }
        berderStorageEl.innerHTML = allTheburgersHtml;
        devouredberdersEl.innerHTML = allTheDevouredHambersHtml;
    }
    catch(err){
        console.log("Error calling backend to get all the burgers: ", err);
    }
    try{
        await startDevourBtns()
    }
    catch(err){
        console.log("Error starting event listeners for devour btns: ", err)
    }
}
async function displayburgers ( ) { try { let allTheburgersHtml = "" ; let allTheDevouredHambersHtml = "" ; const { data : allburgers } = await axios . get ( "/api/burger" ) for ( let i = 0 ; i < allburgers . length ; i ++ ) { const { id , burger_name : burgerName , devoured } = allburgers [ i ] if ( devoured ) { const devouredburgerHtml = ` ${ id } ${ id } ${ burgerName } ` allTheDevouredHambersHtml += devouredburgerHtml ; } else { const devouredburgerHtml = ` ${ id } ${ id } ${ burgerName } ${ id } ` allTheburgersHtml += devouredburgerHtml ; } } berderStorageEl . innerHTML = allTheburgersHtml ; devouredberdersEl . innerHTML = allTheDevouredHambersHtml ; } catch ( err ) { console . log ( "Error calling backend to get all the burgers: " , err ) ; } try { await startDevourBtns ( ) } catch ( err ) { console . log ( "Error starting event listeners for devour btns: " , err ) } }
displays all the berders in the db
displays all the berders in the db
// Loops through all the burgers in the DB  // Updates the html elements