Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
  <div class="row text-center">
    <h3>
      Feeling hungry?
    </h3>
    <h5>Get a random meal by clicking below</h5>
    <button class="meal-btn" id="get_meal">Get Meal <i class="fas fa-utensils"></i></button>
    <button class="prev meal-btn" id="last_meal">Previous Meal <i class="fas fa-utensils"></i></button>

  </div>
  <div id="meal" class="row meal"></div>
  <div id="previous" class="prev"></div>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Muli&display=swap");

* {
  box-sizing: border-box;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 30px 0;
  min-height: calc(100vh - 60px);
}

img {
  max-width: 100%;
}

p {
  margin-bottom: 5px;
}

h3 {
  margin: 0;
  font-weight: bold;
}

#meal h2,
#meal h5,
#meal h3 {
  font-weight: bold;
}

#meal h3 {
  margin-bottom: 15px;
}

#meal li {
  margin-left: 15px;
}

#meal h5 {
  margin: 10px 0;
}

li {
  margin-bottom: 0;
}

.fa-utensils {
  font-size: 1.5rem;
  margin-left: 5px;
}

.meal {
  margin: 20px 0;
}

.text-center {
  text-align: center;
}

.videoWrapper {
  position: relative;
  padding-bottom: 56.25%;
  padding-top: 25px;
  height: 0;
}

.videoWrapper iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.meal-overview {
  display: flex;
  flex-wrap: wrap;
}

.info-col {
  flex: 1 1 30%;
  margin-right: 25px;
  background-color: #f7f7f7;
  padding: 15px;
  border: solid 1px #dad9d9;
  filter: drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.7));
}

.info-col img {
  width: 100%;
  /*   min-width: 350px; */
  margin-top: 15px;
  filter: drop-shadow(0px 2px 2px rgba(0, 0, 0, 0.3));
  border: solid 1px #dad9d9;
  border-radius: 8px;
}

.details-col {
  flex: 1 1 65%;
}

.details-copy-container {
  background-color: #063e5e;
  color: #fff;
  padding: 15px;
  border: solid 1px #2d63a3;
  filter: drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.7));
  border-radius: 3px;
  }

.meal-instructions {
  display: block;
  max-height: 525px;
  overflow: hidden;
  overflow-y: auto
}

.meal-vid {
  margin-top: 25px;
  background-color: #f7f7f7;
  padding: 0 15px 15px;
  border: solid 1px #dad9d9;
  filter: drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.7));
  border-radius: 3px;
}

.meal-btn {
  background-color: #2d63a3;
  color: #fff;
  width: 100%;
  max-width: 350px;
  font-size: 1.5rem;
  line-height: 1.5rem;
  margin-bottom: 20px;
  margin-top: -5px;
}

.meal-btn:hover {
  color: yellow;
  transform: scale(1.1);
  transition: auto;
}

.info-col h2 {
  margin-bottom: 0.7rem;
  line-height: 1;
}

              
            
!

JS

              
                // https://www.themealdb.com/api/json/v1/1/random.php

const getMealBtn = document.getElementById("get_meal");
const lastMealBtn = document.getElementById("last_meal");
const lastMealLinks = document.getElementsByClassName("prev-meal-class");

const url = "https://www.themealdb.com/api/json/v1/1/random.php";

const result = document.getElementById("meal");

const previous = document.getElementById("previous");

let prevMealCount = 0;

idsArr = [];

prevMeals = [];

// prevMealName = [];

// const getLast = recentID => {
//   let recentID = prevMealId;
//   return recentId;
// }

getMealBtn.addEventListener("click", (e) => {
  fetch(url)
    .then((res) => res.json())
    .then((res) => {
      // storeId(res.meals[0]);
    // getLastName = res.meals[0].strMeal;
      displayMeal(res.meals[0]);
      prevMeals.push(res.meals[0].idMeal);
      // prevMealName.push(res.meals[0].idMeal);
    prevMealName = res.meals[0].strMeal;
      console.log(`Viewed Meals: ${prevMeals}`);
      console.log(`Most Recent Meal: ${prevMeals}`);
    console.log(`Most Recent Meal NAME: ${prevMealName}`);
    })
    .catch(function (error) {
      console.log(error);
    });
  e.preventDefault();
});

lastMealBtn.addEventListener("click", (e) => {
  // backOne = idsArr[idsArr.length - 2];
  getLast = prevMeals[prevMeals.length - 2];
  getLast = prevMeals[1];
  fetch(`https://www.themealdb.com/api/json/v1/1/lookup.php?i=${getLast}`)
    .then((res) => res.json())
    .then((res) => {
      displayMeal(res.meals[0]);
    console.log(prevMeals);
    })
    .catch(function (error) {
      console.log(error);
    });
  e.preventDefault();
});

// lastMealLinks.addEventListener("click", (e) => {

//   fetch(`https://www.themealdb.com/api/json/v1/1/lookup.php?i=${getLast}`)
//     .then((res) => res.json())
//     .then((res) => {
//       displayMeal(res.meals[0]);
//     console.log(prevMeals);
//     })
//     .catch(function (error) {
//       console.log(error);
//     });
//   e.preventDefault();
// });

// const storeId = mealId => {
//   lastId = mealId.idMeal;
//   console.log(lastId);
//   return lastId;
// }



// function confirm_alert(node) {
//     return confirm(`${lastMealLinks}.href`);
// };

// for(var i=0;i<all.length;i++)
//     all[i].onclick=function(){
//         this.innerHTML = 'New Text';
//     }

const displayMeal = (meal) => {
  
  getMealBtn.firstChild.textContent = "Get New Meal ";
  let mealName = meal.strMeal;
  const ingredients = [];
  
  for (let i = 1; i <= 20; i++) {
    if (meal[`strIngredient${i}`]) {
      ingredients.push(
        `${meal[`strIngredient${i}`]} - ${meal[`strMeasure${i}`]}`
      );
    }
  }
  
  result.innerHTML = `
    <div class="meal-overview">
    <div class='info-col'>
      <h2>${meal.strMeal}</h2>
      <span>Cuisine Area: <em>${meal.strArea}</em></span><br>
      <span>Cuisine Category: <em>${meal.strCategory}</em></span>
      <img src="${meal.strMealThumb}" alt="Meal Image">
      <h5>Ingredients:</h5>
				<ul>
					${ingredients
            .map(
              (ingredient) => `<li>
              ${ingredient}
            </li>`
            )
            .join("")}
				</ul>
    </div>
    <div class="details-col">
      <div class="details-copy-container">
      <div class="meal-instructions">
<h3>Meal Instructions</h3>
      <p>${meal.strInstructions}</p>
      </div>
      </div>
    ${
      meal.strYoutube
        ? `
      <div class="meal-vid">
			<h5>Video Recipe</h5>
			<div class="videoWrapper">
				<iframe width="420" height="315"
				src="https://www.youtube.com/embed/${meal.strYoutube.slice(-11)}">
				</iframe>
			</div>`
        : ""
    }
    </div>
    </div>
    </div>
    `;

  previous.innerHTML = `
<h5>Previous Meals:</h5>
				<ul>
					${prevMeals
            .map(
              (prevMeal) => `<li>
              <a class="prev-meal-class" id="prev-meal-link-${prevMealCount++}" href="https://www.themealdb.com/api/json/v1/1/lookup.php?i=${prevMeal}">
              ${prevMeal}</a>
            </li>`
            )
            .join("")}
				</ul>
`;
  
};

// lastMealLinks.addEventListener("click", (e) => {
//   newURL = lastMealLinks.href;
//   fetch(newURL)
//     .then((res) => res.json())
//     .then((res) => {
//       // displayMeal(res.meals[0]);
//     confirm(newURL);
//     })
//     .catch(function (error) {
//       console.log(error);
//     });
//   e.preventDefault();
// });
              
            
!
999px

Console