Programming in JavaScript

-1

How can I create a function in JavaScript that will have a parameter that will receive what the user type on the screen and wants to return an alert with what was typed by the user?

My question is how to get the function to get the inserted text.

    
asked by anonymous 12.04.2018 / 18:12

1 answer

2

By steps:

a) to receive user input and put in a variable:

const nome = prompt('Escreva um nome!');

b) show the text that was entered:

alert(nome);

All together in one function would be:

function pedirNome() {
  const nome = prompt('Escreva um nome!');
  alert('O nome inserido foi:\n\n${nome}');
  return nome;
}

const nomeUtilizador = pedirNome();

// e aqui podes continuar a usar o que o utilizador inseriu
// dentro da variável "nomeUtilizador"
    
12.04.2018 / 19:00