Doubt with college work in javascript using DOM [closed]

-4

Good morning, guys, I have this job to do and deliver tomorrow in the tutorial, but I'm completely lost in how to work out this in notepad ++. Could you please give me a light? I've been trying since 2:00 am and I can not. Thank you in advance.

Create an HTML form with javascript with the following fields:

  • Product value (text field); quantity (text field)

  • The program should calculate the total cost (quantity x value of the product);

  • The program should calculate the profit on each product (product value x 65%);

  • The program should calculate total profit (profit x quantity);

  • The program should calculate taxes on each product (product value + profit x 18.7%);

  • The program should calculate the total tax (taxes * quantity);

  • The program should calculate the sales price (product value + profit + tax);

  • Print all calculations within one paragraph (

    )

    

<title>Trabalho</title>
<script>

function calcularImposto(){
resultado = document.getElementById("resultado");
n1 = document.getElementById("n1").value;
imposto1 = parseFloat(n1)*0.22;
imposto2 = parseFloat(n1)*0.18;

resultado.innerHTML = "imposto 1" + imposto1 + "<br /> Imposto 2 " + imposto2;
}
</script>
</head>
<body>
    <form>
    <label>Número 1:</label>
    <input type="text" name="n1" id="n1" size="5" />
    <br />

    <input type="button" name="botao" id="botao" value="Calcular"  onclick="calcularSoma()" />
</form>

<p>Resultado: <span id="resultado"> 0 </span></p> 
</body>

This is the code that the teacher passed as an example to help with the work itself. My question is how to adapt this code to the exercises. I thought of doing with some variables like this:

var quantidade, produto
var lucro, imposto
var totalCusto, totalImposto, totalLucro
var precoVenda

custo total = quantidade * produto
lucro = (produto / 100) * 65
imposto = ((produto + lucro) / 100) * 18,7
totalLucro = lucro * quantidade
totalImposto = imposto * quantidade
precoVenda = produto + lucro + imposto

But I do not know if it would work. I missed some classes because of work and now I'm kind of desperate.

    
asked by anonymous 08.02.2015 / 11:11

1 answer

1

First you have to read the values of the product and the quantity:

var produto = document.getElementById("produto").value;
var quantidade = document.getElementById("quantidade").value;

You will need to have these fields in your HTML:

<input type="text" id="produto" value="" />
<input type="text" id="quantidade" value="" />

At the end of your javascript, you concatenate everything in a very large string and put it inside the <p> tag like this:

document.getElementById("resultado").innerHTML = suaString;

In addition, in HTML you are using onclick="calcularSoma()" , but in javascript your function is calcularImposto() .

There is one more problem as well. You are calculating the tax variable with a 18,7 number. It should be 18.7 . It's to use period, not comma.

And please, next time put a better title in the question. Titles like "please help me" tend to irritate community members and make them less likely to help.

    
08.02.2015 / 12:00