| @ -1,44 +1,58 @@ | |||||
| const nome = document.querySelector("#nome"); | |||||
| const sobrenome = document.querySelector("#campo_sobrenome"); | |||||
| const email = document.querySelector("#campo_email"); | |||||
| const checknews = document.querySelector("#check").checked; | |||||
| const btnEnviar = document.querySelector("#btn_enviar"); | |||||
| let eventos = []//array de 1000 objetos | |||||
| let categorias = [["formatura","casamento"],["aniversário","shows"],["gospel","infantil"]] | |||||
| let keywords = ["futebol", "dança","praia","skate", "tênis","almoço","janta","lanche","sobremesa","bolo"] | |||||
| for (let i = 0; i <= 1000; i++) { | |||||
| const evento = {} | |||||
| const categoria = Math.trunc(Math.random() * (2) + 0) | |||||
| const titulo = Math.trunc(Math.random() * (10)) | |||||
| if (i % 6 == 0) { | |||||
| //insere na categoria formatura ou casamento | |||||
| evento.categoria = categorias[0][categoria] | |||||
| } else if (i % 5 == 0){ | |||||
| //insere na categoria aniversario ou shows | |||||
| evento.categoria = categorias[1][categoria] | |||||
| } else { | |||||
| //insere na categoria gospel ou infantil | |||||
| evento.categoria = categorias[2][categoria] | |||||
| } | |||||
| evento.titulo = `evento-${i} ${keywords[titulo]}` | |||||
| eventos.push(evento)//adiciona o objeto evento no array eventos | |||||
| let interesse = []; | |||||
| } | |||||
| const contadores = {} | |||||
| function enviaDados() { | |||||
| if (nome.value == "") { | |||||
| alert('nome não preenchido') | |||||
| nome.focus() | |||||
| return | |||||
| } | |||||
| for (const subcategoria of categorias) { | |||||
| for (const categoria of subcategoria) { | |||||
| contadores[categoria] = 0 | |||||
| if (sobrenome.value == "") { | |||||
| alert('sobrenome não preenchido') | |||||
| sobrenome.focus() | |||||
| return | |||||
| } | } | ||||
| if (email.value == "") { | |||||
| alert('email não preenchido') | |||||
| email.focus() | |||||
| return | |||||
| } | |||||
| } | |||||
| interesse.push(nome.value) | |||||
| interesse.push(sobrenome.value) | |||||
| interesse.push(email.value) | |||||
| alert(interesse) | |||||
| const contadorKeywords = {} | |||||
| /*if(checknews.value != ''){ | |||||
| alert('email não preenchido') | |||||
| email.focus() | |||||
| return | |||||
| }*/ | |||||
| for (const keyword of keywords) { | |||||
| contadorKeywords[keyword] = 0 | |||||
| } | |||||
| for (const evento of eventos) { | |||||
| contadores[evento.categoria] += 1 | |||||
| for (const keyword of keywords){ | |||||
| if (evento.titulo.indexOf(keyword) > -1){ | |||||
| contadorKeywords[keyword] = contadorKeywords[keyword] + 1 | |||||
| } | |||||
| } | |||||
| } | } | ||||
| btnEnviar.addEventListener("click", enviaDados) | |||||
| console.log("Array de eventos: ", eventos.slice(0,11)) | |||||
| console.log("Objeto de categorias preenchido:", contadores)//contagem de eventos por categoria | |||||
| console.log("Objeto de keywords preenchido", contadorKeywords)//contagem de eventos por keywords | |||||