Hey everyone, I am following a youtube video that tracks the ticker price action using Python Flash as the back-end, and utilizes JS, HTML, CSS, JQUERY on the front-end however i am receiving an ample amount of errors for JS. I triple checked to make sure i copied exactly how he has written it. The video is 8 months old so I am not sure if this is outdated.
var tickers = JSON.parse(localStorage.getItem( key:'tickers')) || [];
var lastPrices: {} = {};
var counter : number = 15;
function startUpdateCycle() :void {
updatePrices();
var countdown : number = setInterval(handler:function () : void {
counter--;
$('#counter').text(counter);
if (counter <= 0) {
updatePrices();
counter = 15;
}
}, timeout: 1000)
}
$(document).ready(function () :void {
tickers.forEach(function(ticker: T) :void {
addTickerToGrid(ticker);
});
updatePrices();
$('#add-ticker-form').submit(function(e) :void {
e.preventDefault();
var newTicker = $('#new-ticker').val().toUpperCase();
if (!tickers.includes(newTicker)) {
tickers.push(newTicker);
localStorage.setItem('tickers', JSON.stringify(tickers))
addTickerToGrid(newTicker);
}
$('new-ticker').val(' ');
updatePrices();
});
$('#tickers-grid').on('click', '.remove-btn', funtion() : void {
var tickerToRemove = $(this).data('ticker');
tickers = ticker.filter(t => t !== tickerToRemove);
localStorage.setItem('tickers', JSON.stringify(tickers))
$('#${tickerToRemove}').remove();
});
startUpdateCycle();
});
function addTickerToGrid(ticker) :void {
$('#tickers-grid').append('<div id="${ticker}" class="stock-box"><h2>${ticker}</h2><p id="${ticker}-price"</p><p id="${ticker}-pct"</p><button class="remove-btn" data-ticker="${ticker}">Remove</button></div>')
}
function updatePrices() :void {
tickers.forEach(function (ticker) :void {
$.ajax({
url: '/get_stock_data',
type: 'POST',
data: JSON.stringify(value: {'ticker': ticker}),
contentType: 'application/json; charset=utf-8',
dataType: 'json'
success: funtion (data) :void {
var changePercent : number = ((data.currentPrice - data.openPrice) / data.openPrice) * 100;
var colorClass;
if (changePercent <= -2){
colorClass = 'dark-red'
} else if (changePercent < 0) {
colorClass = 'red'
} else if (changePercent == 0){
colorClass = 'gray'
} else if (changePercent <= 2){
colorClass = 'green'
} else{
colorClass = 'dark-green'
}
$('#${ticker}-price').text('$${data.currentPrice.toFixed(2)}');
$('#${ticker}-pct').text('${changePercent.toFixed(2)}%');
$('#${ticker}-price').removeClass('dark-red red grey green dark-green').addClass(colorClass);
$('#${ticker}-pct').removeClass('dark-red red grey green dark-green').addClass(colorClass);
var flashClass;
if (lastPrices[ticker] > data.currentPrice) {
flashClass = 'red-flash';
} else if (lastPrices[ticker] < data.currentPrice) {
flashClass = 'green-flash';
} else {
flashClass = 'gray-flash';
}
lastPrices[ticker] = data.currentPrice;
$('#${ticker}').addClass(flashClass);
setTimeout(handler: funtion() :void {
$('#${ticker}').removeClass(flashClass);
}, 1000);
}
});
});
}
tickers.forEach(function(ticker: T) : void {
addTickerToGrid();
});
})