-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (35 loc) · 1.34 KB
/
app.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
document.addEventListener('DOMContentLoaded', function() {
// Adiciona um ouvinte de eventos para detectar a tecla Enter
document.getElementById('campo-pesquisa').addEventListener('keydown', function(event) {
if (event.key === 'Enter') {
event.preventDefault(); // Previne o comportamento padrão do Enter
pesquisar(); // Chama a função de pesquisa
}
});
});
function pesquisar() {
let section = document.getElementById("resultado-pesquisa");
let campoPesquisa = document.getElementById("campo-pesquisa").value.trim().toLowerCase();
let resultados = "";
let encontrouReceita = false;
for (let receita of receitas) {
if (receita.nome.toLowerCase().includes(campoPesquisa)) {
resultados += `
<div class="item-card">
<h2>${receita.nome}</h2>
<p>${receita.descricao}</p>
<a href="${receita.link}" target="_blank">Ver Receita</a>
</div>
`;
encontrouReceita = true;
}
}
if (!encontrouReceita) {
resultados = `
<div class="item-card">
<p>Receita não encontrada no momento, volte mais tarde!</p>
</div>
`;
}
section.innerHTML = resultados;
}