alert text & variable JavaScript

36,769

Solution 1

alert('Your text goes here'+your var goes here);

I find out the code I should have put

Solution 2

var name = "John Doe";

function myFunction() {
  alert('Hello ' + name);
}
<button onclick="myFunction()">Checkout</button>

Share:
36,769
Vadim Kotov
Author by

Vadim Kotov

Updated on July 16, 2020

Comments

  • Vadim Kotov
    Vadim Kotov almost 4 years

    Can I put both text and variable in the same alert box I thought the code down would work but it didn't

    alert('text'Variable);

    • Koby Douek
      Koby Douek about 7 years
      Where is Total defined? Please share your full code.
    • mplungjan
      mplungjan about 7 years
      It WOULD work if you had defined Total somewhere