JSFiddle - React, Tailwind, and code Playground

by somya_kashyap3

HTML

<head>
  <title>Ajax calls for quotes</title>
  <script src="https://code.jquery.com/jquery-latest.min.js"></script>
</head>
<form  onsubmit = "quote(); return false;" id = "myForm">
            <input autocomplete="off" autofocus id="symbol" placeholder="Symbol" type="text"/>
            <input type="submit" value="Get Quote"/>
</form>
<p id="quote"></p>

JavaScript

function quote(){
    var url = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&apikey=NAJXWIA8D6VN6A3K&symbol=' + 		$('#symbol').val();
    var d = new Date;
    if(d.getDay() == 6 || d.getDay() == 0){
         alert('Daily shares are not available on Weekend!');
    }
    else{
       $.getJSON(url, function(data) {
       var month = d.getMonth()+1;
       var day = d.getDate();
       var output = d.getFullYear() + '-' + (month<10 ? '0' : '') + month + '-' + (day<10 ? '0' : '') + day;
       $("#quote").html("A share of " + data["Meta Data"]["2. Symbol"] + " has an opening price of " + 
       data["Time Series (Daily)"][output]["1. open"] + " on " + output);
       $("#symbol").val("");
         });
                  }  

                
            }