-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
111 lines (92 loc) · 3.95 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
var firstNameInput = document.querySelector("#first-name");
var lastNameInput = document.querySelector("#last-name");
var emailInput = document.querySelector("#email");
var passwordInput = document.querySelector("#password");
var signUpButton = document.querySelector("#sign-up");
signUpButton.addEventListener("click", function(event) {
event.preventDefault();
// create user object from submission
var user = {
firstName: firstNameInput.value.trim(),
lastName: lastNameInput.value.trim(),
email: emailInput.value.trim(),
password: passwordInput.value.trim()
};
// set new submission to local storage
localStorage.setItem("user", JSON.stringify(user))
window.location.href= "index2.html"
});
function temp(){
var profile = localStorage.getItem("user")
console.log(profile)
}
// // local storage ingredients:
// var veggiesInput = document.getElementById("veggies");
// var proteinsInput = document.getElementById("proteins");
// var condimentsInput = document.getElementById("condiments");
// // check local storage for ingredients:
// var ingredientInfo = JSON.parse(localStorage.getItem("ingredientInfo"));
// var veggies = JSON.parse(localStorage.getItem("veggie"));
// var proteins = JSON.parse(localStorage.getItem("proteins"));
// var condiments = JSON.parse(localStorage.getItem("condiments"));
// if (ingredientInfo){
// veggiesInput.value = ingredientInfo.veggies;
// proteinsInput.value = ingredientInfo.proteins;
// condimentsInput.value = ingredientInfo.condiment;
// };
// const inputEl = document.getElementById('user-input');
// const badgesEl = document.getElementById('badges');
// badgesEl.style = 'display: flex';
// //var allIngredients = [];
// var ingredientsArray = [];
// document.getElementById('add').addEventListener('click', function () {
// var userIngredient = inputEl.value;
// ingredientsArray = JSON.parse(localStorage.getItem('ingredients'))
// if (ingredientsArray.length >= 3) {
// document.getElementById('warning').textContent = 'up to 3!!'
// } else {
// ingredientsArray.push(userIngredient)
// //ingredientsArray.push(ingredient);
// localStorage.setItem('ingredients', JSON.stringify(ingredientsArray));
// }
// loadIngredients();
// inputEl.value = '';
// })
// loadIngredients();
// document.getElementById('wand-btn').addEventListener('click', function () {
// // call api with all ingredients.
// fetchRecipe();
// })
// function loadIngredients() {
// if (localStorage.getItem('ingredients')) {
// ingredientsArray = JSON.parse(localStorage.getItem('ingredients'))
// }
// badgesEl.innerHTML = ''
// for (var i = 0; i < ingredientsArray.length; i++) {
// var divEl = document.createElement('div');
// var buttonEl = document.createElement('button');
// divEl.textContent = ingredientsArray[i];
// divEl.style = "border: 1px solid grey; padding: 3px 5px; margin: 5px";
// divEl.setAttribute('id', ingredientsArray[i]);
// buttonEl.innerHTML = "<span style='color:red'> X </span>";
// buttonEl.classList.add('delete');
// buttonEl.setAttribute('id', ingredientsArray[i]);
// buttonEl.setAttribute('data-text', ingredientsArray[i]);
// divEl.appendChild(buttonEl);
// badgesEl.appendChild(divEl);
// }
// var deleteEl = document.querySelectorAll('.delete')
// deleteEl.forEach((button) => {
// button.addEventListener('click', function() {
// var deleteIngredient = button.parentNode
// deleteIngredient.remove();
// var ingredientsArray = JSON.parse(localStorage.getItem('ingredients'));
// var ingredientIndex = ingredientsArray.indexOf(`${button.id}`);
// if (ingredientIndex > -1){
// ingredientsArray.splice(ingredientIndex, 1)
// }
// localStorage.setItem('ingredients', JSON.stringify(ingredientsArray));
// console.log(button.id);
// })
// });
// }