-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarquee.js
26 lines (26 loc) · 1.4 KB
/
marquee.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Marquee{
constructor(element){
this.marqueeElement = element;
const theUrl = `https://stock-exchange-dot-full-stack-course-services.ew.r.appspot.com/api/v3/quote/`;
const companiesMarquee = "GOOG, AAPL, DBX, WYNN, BYND, TSLA, FL, MSFT, AMZN, FB, BRK-B, FIZZ, NVDA, IRBT, BA, DIS, GE, HD, NKE, SBUX, JNJ, PEP, MMM, V, WM, JPM, LMT, LEG, GM, LUV, GS, DAL, BK-PC, AXP, KO, WFC, BAC, UBER, SWKS, QCOM, SCHW";
this.mainFunc(theUrl, companiesMarquee);
}
mainFunc(url, ext){
marqueeData(url, ext).then(data =>{
for(let i = 0; i < data.length; i++){
let newSpan = document.createElement('span');
let newSpanInside = document.createElement('span');
this.marqueeElement.appendChild(newSpan);
this.marqueeElement.appendChild(newSpanInside);
newSpan.textContent = `${data[i].symbol}: $${data[i].price} `;
if(Math.sign(data[i].changesPercentage) === 1){
newSpanInside.textContent = `(+${data[i].changesPercentage}%) `;
newSpanInside.classList.add('company-green');
} else if(Math.sign(data[i].changesPercentage) === -1){
newSpanInside.textContent =`(${data[i].changesPercentage}%) `;
newSpanInside.classList.add('company-red');
}
}
})
}
}