Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

131
Visualizações
javascript function returning function instead of float/object

i have a function where im returning some html element, before i return it, if i console.log() it it outputs the numerical value eg. 1234... however its typeof() is "object" even though i have parseFloated() it... after returning it, it returns as a typeof() as function... im trying to pass the return value through to another function, can someone please explain to me what is going wrong? how do i keep the return value as an object or float rather then a function so i can then pass it?

async function checkPrice(page) {
    await page.reload();
    await page.waitForNavigation();
    await page.waitForTimeout(2000); // network idle2 not working... this is sufficient

    var html = await page.evaluate(() => {
        const buyTag = document.querySelectorAll(".MuiButton-root.MuiButton-contained.MuiButton-containedPrimary.MuiButton-sizeMedium.MuiButton-containedSizeMedium.MuiButton-disableElevation.MuiButtonBase-root.color-tertiary.css-k5syhx .css-gmuwbf");

        let prices = [];

        buyTag.forEach((tag) => {  

            if(tag.innerHTML[0] === '$' ) {
                var string = tag.innerHTML;
                var float  = parseFloat(string.replace(/[^0-9.-]+/g, ''));
                if(prices.length < 1) {
                   prices.push(float)
            }}
        });
        return prices
    });
    // console.log(html) returns 1234, typeof() is obj here
    return html
}
// console.log(html) returns a function here
async function priceUpdate(html) { 

    let new_price = []; 
    let old_price = [];

    if(new_price.length < 1) {
        new_price.push(html);
    }
    if(new_price.length > 0) {
        old_price.pop();
        old_price.push(new_price);
        new_price.pop();
        new_price.push(html);
    }
    if(parseFloat(new_price[0]) != 
    parseFloat(old_price[0])) {
        console.log('lowest price changed from: $' + old_price + ' to: ' + '$ ' + new_price);
    }
    else {
        console.log('current price: $' + old_price);
    };
}

async function monitor() {
    let page = await configureBrowser();
    for(var i=0; i=1000; i++) {
        await checkPrice(page);
        await priceUpdate(html);
    }}

monitor()
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda