JAVASCRIPT advance course foundation super challenge

Here is my code friends! please look it and give me your view on this.

import getStockData from “./fakeStockAPI.js”

let previousPrice = null;

function renderStockTicker(stockData) {

const { name, sym, price, time } = stockData
const stockDisplayName = document.getElementById(‘name’).textContent = name
const stockDisplaySymbol = document.getElementById(‘symbol’).textContent = sym
const stockDisplayPrice = document.getElementById(‘price’).textContent = price
const stockDisplayTime = document.getElementById(‘time’).textContent = time

const icon = previousPrice > price ? “red.svg” : previousPrice < price ? “green.svg” : “grey.svg”

const stockDisplayPriceIcon = document.getElementById(‘price-icon’).innerHTML = <img src="./svg/${icon}"/>

previousPrice = price

}

setInterval(() => {
renderStockTicker(getStockData())
}, 1500)

renderStockTicker(getStockData())

Great effort on this! You’re on the right track. Here are some improvements from my review:

  • I don’t think you need to assign the const values the the textContent changes as you can directly update the DOM elements without extra variables. Unless you’re using this later down the line somewhere in your code too, but just a note.

  • document.getElementById(‘price-icon’).innerHTML = <img src="./svg/${icon}"/> Not sure if this works for you, might have to use template literals (backticks) to get it working.

  • Right now, the first stock update only happens after 1.5 seconds. Was this intended? Not, you can call the function before the interval so get it to run immediately.