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

154
Visualizações
My value1.length is receiving a length undefined error. The value2.length and value3.length aren't receiving errors

Value1.length is sending a undefined error however the other two values are not. Why is it only the first value isn't running properly?

placeOrder.addEventListener("click", function (e) {
    e.preventDefault();

    var value1 = input1.value;
    if (value1.length < 1) {
        value1 = 0;
        coffeeTotal = 0;
    } else {
        coffeeTotal = coffeePrice * parseInt(value1);
    }

    var value2 = input2.value;
    if (value2.length < 1) {
        value2 = 0;
        bagelTotal = 0;
    } else {
        bagelTotal = bagelPrice * parseInt(value2);
    }

    var value3 = input3.value;
    if (value3.length < 1) {
        value3 = 0;
        biscottiTotal = 0;
    } else {
        biscottiTotal = biscottiPrice * parseInt(value3);
    }

    var total = coffeeTotal + bagelTotal + biscottiTotal;
    console.log(total);


});
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

What does typeerror: cannot read property “values” from undefined really mean?

To understand this, you first need to understand what it means to be undefined in JavaScript. Let’s take a look at a simple example using variables:

// This line is a variable declaration
// we create it, but do not assign it a value 
// so it is undefined
var a; 
// In this line we declare and assign a variable
// this is not undefined 
var b = 6;

Something is undefined when it is an object that is expected to hold a reference to a value, but in fact references nothing. So you have to check your input1's value.

about 4 years ago · Juan Pablo Isaza Relatório
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