1
resposta

Não consigo achar o erro

o codigo nao funcina e nao apresenta nenhum erro de sintaxe. Consigo achar onde estou errando. quando clikar em adiciona deveria mostrar o que foi escrito no input

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="css/">
    <title>Exercicio D</title>
</head>
<body>
    <h1>Programa Ultimas Noticias</h1>

    <p>Noticias:
        <input type="text" id="inNoticia">
        <input type="button" value="Adicionar" id="btAdicionar">
        <input type="button" value="Listar ultimas noticias" id="btListar">
    </p>

    <p id="outCadastradas"></p>
    <pre id="outNoticias"></pre>

    <script src="exerc5_4.js"></script>
</body>
</html>
var noticias = [];

function adiciona(){
    let inNoticia = document.getElementById("inNoticia");
    let noticia = inNoticia.value;

    if(noticia = ""){
        alert("Preencha os campos corretamente");
        inNoticia.focus();
        return;
    }

    noticias.push(noticia)

    inNoticia.value = "";
    inNoticia.focus();

    listarNoticias();
    console.log(noticias)
}

var btAdicionar = document.getElementById("btAdicionar");
btAdicionar.addEventListener("click", adiciona);

function listarNoticias(){
    var lista = "";

    for (var i = 0; i < noticias.length; i++){
        lista += lista + noticias[i] + "\n"
    }
    document.getElementById("outNoticias").textContent = lista;
}

1 resposta

Esse comando deixa tudo vazio. inNoticia.value = "";

Se te ajudou marca como resolvido para mais pessoas entenderem sua solução!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software