diff --git a/student-projects/day1/calculator.js b/student-projects/day1/calculator.js new file mode 100644 index 00000000..498c7f54 --- /dev/null +++ b/student-projects/day1/calculator.js @@ -0,0 +1,35 @@ +function calculate(operation) { + const num1 = parseFloat(document.getElementById("num1").value); + const num2 = parseFloat(document.getElementById("num2").value); + let result; + + if (isNaN(num1) || isNaN(num2)) { + result = 'Please enter valid numbers.'; + } else { + switch (operation) { + case 'add': + result = num1 + num2; + break; + case 'subtract': + result = num1 - num2; + break; + case 'multiply': + result = num1 * num2; + break; + case 'divide': + if (num2 === 0) { + result = 'Cannot divide by zero.'; + } else { + result = num1 / num2; + } + break; + case 'modulo': + result = num1 % num2; + break; + default: + result = 'Invalid operation.'; + } + } + + document.getElementById("result").innerHTML = 'Result: ' + result; +} \ No newline at end of file diff --git a/student-projects/day1/index.html b/student-projects/day1/index.html new file mode 100644 index 00000000..f47046e6 --- /dev/null +++ b/student-projects/day1/index.html @@ -0,0 +1,22 @@ + + + + Calculator + + + +
+

Calculator

+ + +
+ + + + + +
+

+
+ + \ No newline at end of file diff --git a/student-projects/day2/recipe..html b/student-projects/day2/recipe..html new file mode 100644 index 00000000..218dc551 --- /dev/null +++ b/student-projects/day2/recipe..html @@ -0,0 +1,39 @@ + + + + + + Recipe Book + + + +
+

Recipe Book

+
+

Add New Recipe

+
+ + + + + + + +
+
+
+

Recipes

+ +
+ +
+ + + \ No newline at end of file diff --git a/student-projects/day2/recipe.js b/student-projects/day2/recipe.js new file mode 100644 index 00000000..cf189716 --- /dev/null +++ b/student-projects/day2/recipe.js @@ -0,0 +1,62 @@ +const recipeForm = document.getElementById('recipeForm'); +const recipeList = document.getElementById('recipeList'); +const modalTitle = document.getElementById('modalTitle'); +const modalIngredients = document.getElementById('modalIngredients'); +const modalDescription = document.getElementById('modalDescription'); +const modal = document.getElementById('recipeDetails'); +const closeModal = document.getElementsByClassName('close')[0]; + +let recipes = JSON.parse(localStorage.getItem('recipes')) || []; + +// Function to add a new recipe +function addRecipe(event) { + event.preventDefault(); + + const recipeName = document.getElementById('recipeName').value; + const ingredients = document.getElementById('ingredients').value; + const description = document.getElementById('description').value; + + const recipe = { name: recipeName, ingredients, description }; + recipes.push(recipe); + localStorage.setItem('recipes', JSON.stringify(recipes)); + displayRecipes(); + recipeForm.reset(); +} + +// Function to display recipes +function displayRecipes() { + recipeList.innerHTML = ''; + recipes.forEach((recipe, index) => { + const listItem = document.createElement('li'); + listItem.textContent = recipe.name; + listItem.addEventListener('click', () => showRecipeDetails(index)); + recipeList.appendChild(listItem); + }); +} + +// Function to show recipe details in modal +function showRecipeDetails(index) { + const recipe = recipes[index]; + modalTitle.textContent = recipe.name; + modalIngredients.textContent = 'Ingredients: ' + recipe.ingredients; + modalDescription.textContent = 'Description: ' + recipe.description; + modal.style.display = 'block'; +} + +// Event to close the modal +closeModal.onclick = function() { + modal.style.display = 'none'; +}; + +// Event to close the modal if clicked outside of it +window.onclick = function(event) { + if (event.target == modal) { + modal.style.display = 'none'; + } +}; + +// Event to handle form submission +recipeForm.addEventListener('submit', addRecipe); + +// Display the initial list of recipes on page load +window.onload = displayRecipes; \ No newline at end of file