0

I have a problem with php. I was trying to make a button that changes its text into random numbers every time I click, but it only worked for once.

My Code:

<!DOCTYPE html>
<html>
 <body>
  <?php
            function yeet(){
                return rand(1, 100);
            }
        ?>
  <script type="text/javascript">
   function yeeb(){
    let randNum = <?php echo yeet();?>;
    document.getElementById("co").innerHTML = randNum.toString();
   }
  </script>
  <button onclick = "yeeb()" id="co">click</button>
 </body>
</html>

Any help would be grateful.

1 Answers1

0

Why are you doing it using php? You can make that function by javascript only

function yeeb(){
    let randNum = Math.floor(Math.random() * 100) + 1;
    document.getElementById("co").innerHTML = randNum.toString();
}
mustafaj
  • 305
  • 1
  • 12