Why my onclick function in button that is echo by php cannot work?

  echo, html, javascript, onclick, php

I do not know why this cannot work. It can output a button element but the onclick function cannot work at all. Not even an alert box pop up. PLS help.

<!DOCTYPE html>
    <?php $name = "John"; 
    echo "<button type='button' onclick='callYou('".$name."')'> click me </button>";
      function callYou(name) {
          if(confirm("Are you sure?")) {
             $greeting = "hello"+name;
             echo $greeting;
          } else {
             echo "nothing";

Source: Ask PHP