public/js/weeklyplan.js
// http requests with the weeklyURL, one function for each day
http requests with the weeklyURL, one function for each day
http requests with the weeklyURL one function for each day
function weeklyHttpRequestMonday() {
    $.ajax({
        url: weeklyURL,
        type: 'GET',
        success: function (res) {
            console.log(res);
            let cardBody = document.getElementsByClassName('monday')
            let cardBodyChildren;
            for (let i = 0; i < cardBody.length; i++) {
                cardBodyChildren = cardBody[i].children;
                cardBodyChildren[0].textContent = res.week.monday.meals[i].title;
            };
            let planBtnsMonday = document.getElementsByClassName('planBtnsMonday')
            let planBtnsChildren;
            for (let i = 0; i < planBtnsMonday.length; i++) {
                planBtnsChildren = planBtnsMonday[i].children;
                planBtnsChildren[1].href = res.week.monday.meals[i].sourceUrl;
            };
            const imageLink = "https://spoonacular.com/recipeImages/";
            const imageSize = "312x231"
            function imageOneMonday() {
                let imageFormat = "." + res.week.monday.meals[0].imageType
                let imageID = res.week.monday.meals[0].id + "-";
                let imageURL = imageLink + imageID + imageSize + imageFormat;
                let img = document.createElement("img")
                img.src = imageURL
                let src = document.querySelector('.recipeImgBreakfastMonday')
                src.appendChild(img)
            }
            imageOneMonday();
            function imageTwoMonday() {
                let imageFormat = "." + res.week.monday.meals[1].imageType
                let imageID = res.week.monday.meals[1].id + "-";
                let imageURL = imageLink + imageID + imageSize + imageFormat;
                let img = document.createElement("img")
                img.src = imageURL
                let src = document.querySelector('.recipeImgLunchMonday')
                src.appendChild(img)
            }
            imageTwoMonday();
            function imageThreeMonday() {
                let imageFormat = "." + res.week.monday.meals[2].imageType
                let imageID = res.week.monday.meals[2].id + "-";
                let imageURL = imageLink + imageID + imageSize + imageFormat;
                let img = document.createElement("img")
                img.src = imageURL
                let src = document.querySelector('.recipeImgDinnerMonday')
                src.appendChild(img)
            }
            imageThreeMonday();
        },
        dataType: "json",
        error: function () {
            alert("Couldn't retrieve daily meal plan. Please try again.");
        },
    });
}
function weeklyHttpRequestMonday ( ) { $ . ajax ( { url : weeklyURL , type : 'GET' , success : function ( res ) { console . log ( res ) ; let cardBody = document . getElementsByClassName ( 'monday' ) let cardBodyChildren ; for ( let i = 0 ; i < cardBody . length ; i ++ ) { cardBodyChildren = cardBody [ i ] . children ; cardBodyChildren [ 0 ] . textContent = res . week . monday . meals [ i ] . title ; } ; let planBtnsMonday = document . getElementsByClassName ( 'planBtnsMonday' ) let planBtnsChildren ; for ( let i = 0 ; i < planBtnsMonday . length ; i ++ ) { planBtnsChildren = planBtnsMonday [ i ] . children ; planBtnsChildren [ 1 ] . href = res . week . monday . meals [ i ] . sourceUrl ; } ; const imageLink = "https://spoonacular.com/recipeImages/" ; const imageSize = "312x231" function imageOneMonday ( ) { let imageFormat = "." + res . week . monday . meals [ 0 ] . imageType let imageID = res . week . monday . meals [ 0 ] . id + "-" ; let imageURL = imageLink + imageID + imageSize + imageFormat ; let img = document . createElement ( "img" ) img . src = imageURL let src = document . querySelector ( '.recipeImgBreakfastMonday' ) src . appendChild ( img ) } imageOneMonday ( ) ; function imageTwoMonday ( ) { let imageFormat = "." + res . week . monday . meals [ 1 ] . imageType let imageID = res . week . monday . meals [ 1 ] . id + "-" ; let imageURL = imageLink + imageID + imageSize + imageFormat ; let img = document . createElement ( "img" ) img . src = imageURL let src = document . querySelector ( '.recipeImgLunchMonday' ) src . appendChild ( img ) } imageTwoMonday ( ) ; function imageThreeMonday ( ) { let imageFormat = "." + res . week . monday . meals [ 2 ] . imageType let imageID = res . week . monday . meals [ 2 ] . id + "-" ; let imageURL = imageLink + imageID + imageSize + imageFormat ; let img = document . createElement ( "img" ) img . src = imageURL let src = document . querySelector ( '.recipeImgDinnerMonday' ) src . appendChild ( img ) } imageThreeMonday ( ) ; } , dataType : "json" , error : function ( ) { alert ( "Couldn't retrieve daily meal plan. Please try again." ) ; } , } ) ; }
http requests with the weeklyURL, one function for each day
http requests with the weeklyURL one function for each day
// append recipe titles // append recipe url to show recipe button //image appending //declare variables //first image //first image //first image