let tarefas = [];

function adicionarTarefa(tarefa) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            if (tarefa) {
                tarefas.push(tarefa);
                resolve(`Tarefa "${tarefa}" adicionada com sucesso!`);
            } else {
                reject("Erro: informe uma tarefa.");
            }
        }, 1000);
    });
}

function removerTarefa(tarefa) {
    return new Promise((resolve, reject) => {
        setTimeout(() => {
            let indice = tarefas.indexOf(tarefa);

            if (indice !== -1) {
                tarefas.splice(indice, 1);
                resolve(`Tarefa "${tarefa}" removida com sucesso!`);
            } else {
                reject(`Erro: a tarefa "${tarefa}" não foi encontrada.`);
            }
        }, 1000);
    });
}

async function gerenciarTarefas() {
    try {
        console.log(await adicionarTarefa("Estudar JavaScript"));
        console.log(await adicionarTarefa("Fazer atividade"));
        console.log(await adicionarTarefa("Revisar Promises"));

        console.log("Tarefas:", tarefas);

        console.log(await removerTarefa("Fazer atividade"));

        console.log("Tarefas finais:", tarefas);
    } catch (erro) {
        console.log(erro);
    }
}

gerenciarTarefas();

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: