Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BarmanApp Project Submission #30

Open
2 of 6 tasks
goran2308 opened this issue Dec 1, 2019 · 12 comments
Open
2 of 6 tasks

BarmanApp Project Submission #30

goran2308 opened this issue Dec 1, 2019 · 12 comments

Comments

@goran2308
Copy link

goran2308 commented Dec 1, 2019

Project Name / Title

Barman App

Your Name / Title

Goran

Project Description

This app allows you to find your favourite cocktail recipe. Good if you want to impress your friends at the parties. Enjoy!

What 3rd Party Web API do you plan to use?

Which of the following describes you:

  • YouTube Subscriber
  • Twitch Follower
  • Patreon Patron
  • Superchat Donor
  • Streamlabs Donor
  • Coding Garden Moderator
@w3cj
Copy link
Member

w3cj commented Dec 2, 2019

Nice idea! Please fill out the full project description template and add it to your repo: https://raw.githubusercontent.com/CodingGarden/seedling-school-01-frontend-project/master/PROJECT_DESCRIPTION_TEMPLATE.md

@goran2308
Copy link
Author

Changes are done and the project is live: http://barmanapp.surge.sh/

@mahendrjy
Copy link

I like it, It's amazing.

@goran2308
Copy link
Author

@iampika thanks mate. Your project looks great as well. Keep up the good work.

@goran2308
Copy link
Author

goran2308 commented Dec 4, 2019

@w3cj CJ I just need one little thing from you please. Can you explain me how to iterate through the ingredients as they are hard coded for now. First time I am working with API. Thanks.

@mahendrjy
Copy link

mahendrjy commented Dec 4, 2019

Thank you so much for your kind words.

// I assume you already know how to get data from api

// Let's say, from api you get ingredients array which is look something like this
const ingredients = [
  {
    id: 1,
    name: 'apple'
  },
  {
    id: 2,
    name: 'banana'
  },
  {
    id: 1,
    name: 'grapes'
  },
]

// This is where you want to place the iterated data
const myIngredients = document.querySelector('#ingredients');

// How to iterate and place the data into html
ingredients.forEach(ingredient => {
  myIngredients.innerHTML += `<li class="ingredient">${ingredient.name}</li>`
})

@goran2308
Copy link
Author

goran2308 commented Dec 4, 2019

@iampika I get the data like this:

"drinks":
[{"idDrink":"11007",
"strDrink":"Margarita",
"strDrinkAlternate":null,
"strDrinkES":null,
"strDrinkDE":null,
"strDrinkFR":null,
"strDrinkZH-HANS":null,
"strDrinkZH-HANT":null,
"strTags":"IBA,ContemporaryClassic",
"strVideo":null,
"strCategory":"Ordinary Drink",
"strIBA":"Contemporary Classics",
"strAlcoholic":"Alcoholic",
"strGlass":"Cocktail glass",
"strIngredient1":"Tequila",
"strIngredient2":"Triple sec",
"strIngredient3":"Lime juice",
"strIngredient4":"Salt",
"strIngredient5":null,
"strIngredient6":null
]}

So basically I want to take the ingredients only from the object, make an array and remove null values. Later just iterate through the array and console log the values.

@mahendrjy
Copy link

mahendrjy commented Dec 4, 2019

@goran2308 I think you want all the ingredients from all the drinks

const data = {
  drinks: [
    {
      idDrink: '11007',
      strDrink: 'Margarita',
      strDrinkAlternate: null,
      strDrinkES: null,
      strDrinkDE: null,
      strDrinkFR: null,
      'strDrinkZH-HANS': null,
      'strDrinkZH-HANT': null,
      strTags: 'IBA,ContemporaryClassic',
      strVideo: null,
      strCategory: 'Ordinary Drink',
      strIBA: 'Contemporary Classics',
      strAlcoholic: 'Alcoholic',
      strGlass: 'Cocktail glass',
      strIngredient1: 'Tequila',
      strIngredient2: 'Triple sec',
      strIngredient3: 'Lime juice',
      strIngredient4: 'Salt',
      strIngredient5: null,
      strIngredient6: null,
    },
  ],
};

// Getting drinks from data
const { drinks } = data;

// Make an array
const ingredients = [];

// Iterate through the array
drinks.forEach(drink => {
  let num = 1;
  let strIngredient = `strIngredient${num}`;

  while (num <= 6) {
    // remove null values and check if the value is already exist
    if (
      !(drink[strIngredient] === null) &&
      !ingredients.includes(drink[strIngredient])
    ) {
      // add ingredient to the ingredients array
      ingredients.push(drink[strIngredient]);
    }
    num++;
    strIngredient = `strIngredient${num}`;
  }
});

// console log the values
console.log(ingredients); // [ 'Tequila', 'Triple sec', 'Lime juice', 'Salt' 

@goran2308
Copy link
Author

@iampika Cheers mate. After your post I learned about destructuring the objects. It is just amazing what can you do wit all that. I'll try to implement that in the project. Lack of time is my enemy :).

@mahendrjy
Copy link

@goran2308 Your Welcome.

@w3cj
Copy link
Member

w3cj commented Dec 14, 2019

Any updates to share? Let me know if you would like an ui review or code review.

@goran2308
Copy link
Author

goran2308 commented Dec 14, 2019

@w3cj I would like you to review my code and design. Just one other thing if you have time please to explain me how to fix ingredients section. Right now they are hard coded, but I want to make them dynamic. I tried to use the solution from @iampika and I still can't make it work with this API. Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants