How to show value typed in Alert()?

Asked

Viewed 175 times

-2

How to show a variable value string or typed in a prompt?

<script type="text/javascript">
    function funcao()
    {
        var x;
        var quantidade = prompt("Digite valor do saque");
        x = quantidade;
        alert("$quantidade$");
    }
</script>
  • This answers your question? Javascript programming

  • Did any of the answers solve your question? Do you think you can accept one of them? Check out the [tour] how to do this, if you haven’t already. You would help the community by identifying what was the best solution for you. You can accept only one of them. But you can vote on any question or answer you find useful on the entire site (when you have enough score).

2 answers

2

Just print the variable, without anything else, you only use quotation marks to put a text, if you want a symbol of the code to be solved and used its value then it should appear direct. There is even how to put a variable inside the quotes but this is more advanced and does not work in all versions, so it is better not to use for now.

function funcao() {
    var quantidade = prompt("Digite valor do saque");
    alert(quantidade);
}
funcao();

If you want to print a text and the variable can make a simple concatenation:

function funcao() {
    var quantidade = prompt("Digite valor do saque");
    alert("O valor digitado é " + quantidade);
}
funcao();

I put in the Github for future reference.

0

In this way:

"$quantidade$"

You will show the string $quantidade$, to show the value of the variable "quantity", just put the "quantity" in Alert, as in the example below:

function funcao()
{
  var x;
  var quantidade = prompt("Digite valor do saque");
  x = quantidade;
  alert(quantidade);
}
funcao();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.