Search code examples
javascriptalertprompt

alert and prompt javascript


The browser show me "thinksHarry Potter" without space between "thinks" and "harry" words, so my guys can you tell me how can I do that? This is my code:

<!DOCTYPE html>
<html>
  <body>
    <button onclick="myFunction()">Try it</button>

    <script>
      function myFunction() {
        var person = prompt("Please enter your name", "Harry Potter");

        if (person != null) {
          alert("thinks" + person);
        }
      }
    </script>
  </body>
</html>

Solution

  • it's easy man, you have to notice that you have no spaces after the 'thinks' or before 'harry'.

    make a space after think:

    alert('thinks' + person);
    

    or before harry:

    var person=prompt("Please enter your name"," Harry Potter");