Javascript discount for price classes

Ive been trying to add a discount to price classes for a couple of days now but haven’t been able to. The current js code I have is a simple addition calculator, but I want it to discount prices between 100 and 500 with 10% and prices over 500 get 20% discount. I also want it to show the price before and after the discount if possible.

The code I have for the calculator so far, its working fine:

Artikel 1 <input type="text2" id="num1">
<br>
<br>
Artikel 2 <input type="text2" id="num2">
<br>
<br>
<button onclick="calculate()">Totalpris</button>

<script>

function calculate ()
{
  var field1=document.getElementById("num1").value;
  var field2=document.getElementById("num2").value;

  var result=parseFloat(field1)+parseFloat(field2);


if (!isNaN(result))
{
document.getElementById("answer").innerHTML="Totalpris är "+result;
}

}

</script>

<h1 id="answer"></h1>

Thanks for the fast reply. I have been trying a lot of codes and have only been using JavaScript for a couple of days so I don’t know a lot about the discount function. I have also been using this if statement:

if ( totpr >= 100 && totpr < 500 ) {
}

but I don’t know much more than this :frowning: