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.
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.
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"