I'm receiving this error "Uncaught ReferenceError: IXIC is not defined" for my Javascript code. I've defined the global variables "httpRequest" and "entry" before the functions however only the value for "entry" is getting an error. My code below (the assignment is to fetch market information for a stock based on a stock symbol that a user specifies): "use strict"; var httpRequest = false; var entry = IXIC; function getRequestObject () { try { httpRequest = new XMLHttpRequest (); } catch (requestError) { return false; } return httpRequest; } function stopSubmission(evt) { if (evt.preventDefault) { evt.preventDefault (); } else { evt.returnValue = false; } getQuote (); } function getQuote () { if (document.getElementsByTagName ("input")[0].value) { entry = document.getElementsByTagName ("input")[0].value; } if (!httpRequest) { httpRequest = getRequestObject(); } httpRequest.abort(); httpRequest.open ("get", "https://sandbox.iexapis.com/stable/stock/$TickerSymbol/batch?types=quote&range=1m&last=10&token=Tsk_d5ea71c8c07e42938ef76260650e269a" + entry, true); httpRequest.send(); httpRequest.onreadystatechange = displayData; } function displayData () { if (httpRequest.readyState === 4 && httpRequest.status === 200){ var stockResults = httpRequest.responseText; stockResults = httpRequest.responseText; let lenStockResults = stockResults.length; let parseString = stockResults.subString (9, lenStockResults - 1); stockItems = JSON.parse (parseString); var ticker = stockItems.symbol; //stockItems ['symbol'] var closePrice = stockItems.close; var openPrice = stockItems.open; var avgTotalVolume = stockItems.avgTotalVolume; var nf = Intl.NumberFormat (); avgTotalVolume = nf.format (avgTotalVolume); var weekhigh52 = stockItems.weekhigh52; var weekLow52 = stockItems.weekLow52; document.getElementById ("ticker").innerHTML = ticker; document.getElementById ("open").innerHTML = openPrice; document.getElementById ("close").innerHTML = closePrice; document.getElementById ("52weekHigh").innerHTML = weekhigh52; document.getElementById ("52weekLow").innerHTML = weekLow52; document.getElementById ("volume").innerHTML = avgTotalVolume; } } function formatTable () { var rows = document.getElementsByTagName ("tr"); for (var i = 0; i < rows.length; i = i + 2) { rows [i].style.background = "#9FE098"; } } var form = document.getElementsByTagName ("form")[0]; if (form.addEventListener) { form.addEventListener ("submit", stopSubmission, false); window.addEventListener ("load", formatTable, false); window.addEventListener ("load", getQuote, false); } else if (form.attachevent) { form.attachevent ("onsubmit", stopSubmission); window.attachevent ("onload", formatTable); window.attachevent ("onload", getQuote); }
I'm receiving this error "Uncaught ReferenceError: IXIC is not defined" for my Javascript code. I've defined the global variables "httpRequest" and "entry" before the functions however only the value for "entry" is getting an error. My code below (the assignment is to fetch market information for a stock based on a stock symbol that a user specifies):
"use strict";
var httpRequest = false;
var entry = IXIC;
function getRequestObject () {
try {
httpRequest = new XMLHttpRequest ();
}
catch (requestError) {
return false;
}
return httpRequest;
}
function stopSubmission(evt) {
if (evt.preventDefault) {
evt.preventDefault ();
} else {
evt.returnValue = false;
}
getQuote ();
}
function getQuote () {
if (document.getElementsByTagName ("input")[0].value) {
entry = document.getElementsByTagName ("input")[0].value;
}
if (!httpRequest) {
httpRequest = getRequestObject();
}
httpRequest.abort();
httpRequest.open ("get", "https://sandbox.iexapis.com/stable/stock/$TickerSymbol/batch?types=quote&range=1m&last=10&token=Tsk_d5ea71c8c07e42938ef76260650e269a" + entry, true);
httpRequest.send();
httpRequest.onreadystatechange = displayData;
}
function displayData () {
if (httpRequest.readyState === 4 && httpRequest.status === 200){
var stockResults = httpRequest.responseText;
stockResults = httpRequest.responseText;
let lenStockResults = stockResults.length;
let parseString = stockResults.subString (9, lenStockResults - 1);
stockItems = JSON.parse (parseString);
var ticker = stockItems.symbol; //stockItems ['symbol']
var closePrice = stockItems.close;
var openPrice = stockItems.open;
var avgTotalVolume = stockItems.avgTotalVolume;
var nf = Intl.NumberFormat ();
avgTotalVolume = nf.format (avgTotalVolume);
var weekhigh52 = stockItems.weekhigh52;
var weekLow52 = stockItems.weekLow52;
document.getElementById ("ticker").innerHTML = ticker;
document.getElementById ("open").innerHTML = openPrice;
document.getElementById ("close").innerHTML = closePrice;
document.getElementById ("52weekHigh").innerHTML = weekhigh52;
document.getElementById ("52weekLow").innerHTML = weekLow52;
document.getElementById ("volume").innerHTML = avgTotalVolume;
}
}
function formatTable () {
var rows = document.getElementsByTagName ("tr");
for (var i = 0; i < rows.length; i = i + 2) {
rows [i].style.background = "#9FE098";
}
}
var form = document.getElementsByTagName ("form")[0];
if (form.addEventListener) {
form.addEventListener ("submit", stopSubmission, false);
window.addEventListener ("load", formatTable, false);
window.addEventListener ("load", getQuote, false);
} else if (form.attachevent) {
form.attachevent ("onsubmit", stopSubmission);
window.attachevent ("onload", formatTable);
window.attachevent ("onload", getQuote);
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps