Parameterized functions - calculatValue

Asked

Viewed 308 times

-2

I’m taking the first Javascript classes, so my doubts are simple. Enunciation:

After our consultation, Digitallaundry realized that could make your collection more sophisticated and fair. She decided charge R$10.00 fixed, as a service fee (independent of the amount of laundry), plus R $ 3,00 per kilo of laundry. Rewrite the function calculatValue

function calculaValorDevido(pesoDeRoupaSuja){
  ...
}

This function takes as its only parameter the amount of laundry. It should return the amount to be charged to the customer using the new price policy.

My code until then:

console.log(calculaValorDevido(10));



function calculaValorDevido(pesoDaRoupaSuja) {
    var pesoroupaSuja 
    pesoDaRoupaSuja * 3
    var fixo = 10.00
    
      return fixo + pesoDaRoupaSuja
    }

The mistake is:

There’s something wrong with your multiplication, make sure you’re returning multiplication correctly

  • You wrote the statement, an attempt. What doubt after all?

3 answers

1

Consider the following.

First: You’re multiplying the weightDaRoupaSuja by 3, but you’re not saving that new value. Second: You do not need to declare a variable you received as a parameter in the function.

console.log(calculaValorDevido(10));



function calculaValorDevido(pesoDaRoupaSuja) {
    let ValorPeso = pesoDaRoupaSuja * 3;
    var fixo = 10.00;
    
      return fixo + ValorPeso;
    }

  • worked @Beca , Thank you very much!

  • If the answer was helpful, can you mark it as the answer to the question. ;)

0

You can try this way:

  console.log(calculaValorDevido(10));
  
  
  function calculaValorDevido(pesoDaRoupaSuja){
    
    return ( 10 + (pesoDaRoupaSuja * 3))
    
    }

-2

// Configurações
const preco_fixo = 10
const taxa_por_quilo = 3
// Função
function calculaValorDevido(peso_da_roupa) {
  let resultado=peso_da_roupa*taxa_por_quilo; // Aplicando a taxa p/ Kg
  resultado+=preco_fixo; // Adicionando o preço fixo
  return resultado;
}
// Testando
console.log(calculaValorDevido(2))

Browser other questions tagged

You are not signed in. Login or sign up in order to post.