-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathResposta
36 lines (27 loc) · 902 Bytes
/
Resposta
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
const produtos = [];
function adicionarProduto() {
const nomeInput = document.getElementById('valor1');
const descricaoInput = document.getElementById('valor2');
const valorInput = document.getElementById('valor3');
const nome = nomeInput.value;
const descricao = descricaoInput.value;
const valor = valorInput.value;
if (nome && descricao && valor) {
const novoProduto = {
nome: nome,
descricao: descricao,
valor: valor
};
produtos.push(novoProduto);
atualizarTabela();
}
}
function atualizarTabela() {
var divProdutos = document.getElementById("produtos");
divProdutos.innerHTML = "";
for (var i = 0; i < produtos.length; i++) {
var novoElemento = document.createElement("p");
novoElemento.textContent = produtos[i].nome + " : "+ produtos[i].descricao + " : "+ produtos[i].valor ;
divProdutos.appendChild(novoElemento);
}
}