Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 147 additions & 0 deletions student-projects/day2/recipe/meet_ecs67
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
<!DOCTYPE html>x
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Recipe To-Do List</title>
<link rel="stylesheet" href="to.css">
</head>
<body>
<div class="container">
<h1>Recipe To-Do List</h1>
<div id="categories">
<h2>Categories</h2>
<select id="categorySelect" onchange="displayRecipes()">
<option value="All">All</option>
</select>
</div>
<div id="recipes">
<h2>Recipes</h2>
<ul id="recipeList"></ul>
</div>
<div id="ingredients">
<h2>Ingredients</h2>
<ul id="ingredientList"></ul>
</div>
<input type="text" id="searchInput" placeholder="Search recipes" oninput="searchRecipes()">
<input type="text" id="taskInput" placeholder="Search.....">
<button onclick="addTask()">Search</button>
</div>
<script>
let recipes = [
{ category: "Breakfast", name: "Scrambled Eggs", ingredients: ["eggs", "milk", "salt", "pepper"] },
{ category: "Lunch", name: "Caesar Salad", ingredients: ["lettuce", "croutons", "parmesan cheese", "caesar dressing"] },
{ category: "Dinner", name: "Spaghetti Bolognese", ingredients: ["spaghetti", "ground beef", "tomato sauce", "onion", "garlic"] }
];cmd'

const categorySelect = document.getElementById("categorySelect");
const recipeList = document.getElementById("recipeList");
const ingredientList = document.getElementById("ingredientList");

// Populate category dropdown
function populateCategoryDropdown() {
const categories = Array.from(new Set(recipes.map(recipe => recipe.category)));
categories.forEach(category => {
const option = document.createElement("option");
option.textContent = category;
option.value = category;
categorySelect.appendChild(option);
});
}

// Display recipes based on selected category
function displayRecipes() {
const selectedCategory = categorySelect.value;
recipeList.innerHTML = "";

if (selectedCategory === "All") {
recipes.forEach(recipe => {
const li = document.createElement("li");
li.textContent = recipe.name;
li.addEventListener("click", () => {
displayIngredients(recipe.ingredients);
});
recipeList.appendChild(li);
});
} else {
const filteredRecipes = recipes.filter(recipe => recipe.category === selectedCategory);
filteredRecipes.forEach(recipe => {
const li = document.createElement("li");
li.textContent = recipe.name;
li.addEventListener("click", () => {
displayIngredients(recipe.ingredients);
});
recipeList.appendChild(li);
});
}
}

// Display ingredients for a given recipe
function displayIngredients(ingredients) {
ingredientList.innerHTML = "";
ingredients.forEach(ingredient => {
const li = document.createElement("li");
li.textContent = ingredient;
ingredientList.appendChild(li);
});
}

// Function to add a task
function addTask() {
var taskInput = document.getElementById("taskInput");
var taskList = document.getElementById("taskList");

if (taskInput.value === "") {
alert("Please enter a task!");
return;
}

var li = document.createElement("li");
li.textContent = taskInput.value;

var checkBox = document.createElement("input");
checkBox.type = "checkbox";
checkBox.addEventListener("change", function () {
if (this.checked) {
li.classList.add("completed");
} else {
li.classList.remove("completed");
}
});

var deleteButton = document.createElement("button");
deleteButton.textContent = "Delete";
deleteButton.addEventListener("click", function () {
li.remove();
});

li.appendChild(checkBox);
li.appendChild(deleteButton);
taskList.appendChild(li);

taskInput.value = "";
}

// Search recipes based on user input
function searchRecipes() {
const searchInput = document.getElementById("searchInput").value.toLowerCase();
recipeList.innerHTML = "";

recipes.forEach(recipe => {
if (recipe.name.toLowerCase().includes(searchInput)) {
const li = document.createElement("li");
li.textContent = recipe.name;
li.addEventListener("click", () => {
displayIngredients(recipe.ingredients);
});
recipeList.appendChild(li);
}
});
}

// Initialize
populateCategoryDropdown();
displayRecipes();
</script>
</body>
</html>