title: How do I convert my PHP api call into JavaScript?
body: <p>I need to make API calls every time a click event happens. I thought I would try to use JavaScript to make a call even though I have PHP for it; in order to make it reliable. </p>
  
  <p>This is my php code for the API call that I'm making:</p>
  
  <pre><code>      // create curl resource
        $ch = curl_init();
        // set url 
        curl_setopt($ch, CURLOPT_URL, "https://uselessfacts.jsph.pl/random.json?" . 
        "language=en");
  
  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
  
        // $output contains the output json
        $output = curl_exec($ch);
        // close curl resource to free up system resources 
        curl_close($ch);
  
  
        $outputArray = json_decode($output, true);
  
  
        echo "&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;br&gt;" . $outputArray['text'];
  </code></pre>
  
  <p>This is my JavaScript code for the click function:</p>
  
  <pre><code>      $(function() {
  
           $('#b1').click(
  
              function() {
  
                  $('#input').val(val);
  
        } ); });
  </code></pre>
  
  <p>My goal is to translate the same API call I made in PHP into JavaScript. And place it into the function. However, it took me a while to figure out how to set up the API call in the first place. This is why I'm not sure if my API call can be made the same way.</p>