I am trying to return the .data property value of the object that is grabbed after hitting this URL https://jsonmock.hackerrank.com/api/stocks?date=23-February-2000
. but for some reason, it is not returning any result. even though I have a return resultO
Here is the code, I tried to research it but I am a bit stuck thank you!!
async function getStockInformation(date) {
// write your code here
// API endpoint: https://jsonmock.hackerrank.com/api/stocks?date=<date>
// let str = date;
// let leadingNum = "";
// let i = 0;
// while (str[i] != "-") {
// leadingNum += str[i];
// i++;
// }
// let newDate = parseInt(leadingNum);
// newDate = newDate.toString();
// let currentDate = newDate;
// let newstr = date.slice(i, date.length);
// currentDate = currentDate + newstr;
let resultO=""
https.get(
"https://jsonmock.hackerrank.com/api/stocks?date=5-January-2000",
(response) => {
let obj = "";
response.on("data", (res) => {
obj += res;
console.log(obj)
});
response.on("end", () => {
let newt = JSON.parse(obj).data;
resultO=newt[0].open;
// "Open:" + newt[0].open;
// resultO=newt[0].data
// console.log(resultO)
// "High:" + newt[0].high;
// "Low:" + newt[0].low;
// "Close:" + newt[0].close;
});
}
);
return resultO
}