-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
29 lines (28 loc) · 966 Bytes
/
main.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
// create an array of plant objects that give a description of how to care for that plant.
const plants = [
{
name: 'Spider Plant',
care: 'Water once a week and keep in bright, indirect sunlight.'
},
{
name: 'Snake Plant',
care: 'Water once a month and keep in low to bright light.'
},
{
name: 'Peace Lily',
care: 'Water once a week and keep in low to bright light.'
}
];
//link to search form in html
const searchForm = document.querySelector('#search-form');
const careInstructions = document.querySelector('#care-instructions');
searchForm.addEventListener('submit', function(event) {
event.preventDefault();
const searchTerm = event.target.querySelector('input').value;
const plant = plants.find(function(item) {
return item.name.toLowerCase() === searchTerm.toLowerCase();
});
if (plant) {
careInstructions.innerHTML = '<p>' + plant.care + '</p>';
}
})