I've done a JavaScript to calculate discounts for a certain amount, but I do not think it's calculating the percentage correctly. If anyone can help me, I thank you!
I think the percentage values I put in js are wrong because you are not calculating correctly. The installment credit gives an absurd value!
obs: How would you place these discounts only for values above 99.99?
function calcular(){
var x = document.getElementById("valor");
var pagar = document.getElementById("pagar");
var d = document.getElementById("debito");
var parc = document.getElementById("parcelado");
var semp = document.getElementById("semparcelas");
var p = Number(x.value);
var y = p;
var s=0;
if(parc.checked){
y = (y*0.5);
s= p-y;
}
if(semp.checked){
y = (y*0.20);
s= p-y;
}
if(d.checked){
y = (y*0.25);
s= p-y;
}
pagar.value= "Desconto: "+y+". Pagar: "+s;
}
<label for="valor"> Digite o valor da compra: </label> <br>
<input type="text" id="valor" name="valor" required onfocus="fn(this)" onblur="fs(this)">
<br><br>
Qual sua forma de pagamento? <br>
<input type="radio" name ="pagamento" id="debito" value="debito">
<label for="debito"> Débito </label>
<br>
<input type="radio" name="pagamento" id="parcelado" value="parcelado">
<label for="parcelado"> Crédito parcelado </label>
<br>
<input type="radio" name="pagamento" id="semparcelas" value="semparcelas">
<label for="semparcelas"> Crédito sem parcelas</label>
<br></br>
Desconto e valor a pagar: <br>
<input type="text" id="pagar" name="pagar" disabled>
<input id="botao1" type="button" value="Calcular" onclick="calcular()" onmouseover="botao(this)" onmouseout="botao(this)">