Here's the updated script I wrote
<script>
let num1=parseFloat(document.querySelector('#origin').value)
let num2=parseFloat(document.querySelector('#added').value)
let calcProfit=parseFloat(100-num2)
let btn=document.querySelector('#submit')
btn.addEventListener("click", function(event){
event.preventDefault()
const initResult=num1/calcProfit
const finalResult=initResult*100
document.querySelector('span').innerHTML=`${finalResult.toFixed(3)}`
console.log(typeof(finalResult))
if (finalResult.toString().length>3 && finalResult.toString().length<7){
const k=finalResult/1000
document.querySelector('span').innerHTML=`${k.toFixed(1)}k`
}
if (finalResult.toString().length>6 && finalResult.toString().length<10){
const m=finalResult/1000000
document.querySelector('span').innerHTML=`${m.toFixed(1)}M`
}
});
let clr=document.querySelector('#clear');
clr.addEventListener("click", function(e){
window.location.reload()
})
at first run it shows NaN, but when I reload the page everything works just fine. I'm suspecting the clear function because when I first wrote it, it didn't give any errors but the whole app behaved abruptly. In this version the clear button removes the result but doesn't affect it, so when I put new numbers it gives me the old result. I tried innerHTML but that doesn't cut it.