<input id="tal1" type="text" placeholder="Tal 1">
<input id="tal2" type="text" placeholder="Tal 2">
<button type="button" onclick="inputAddition()">Byt mellan addition och subtraktion, mellan de två talen</button>
<div></div>
<div class="output"></div>

<script>
function inputAddition(){
document.getElementsByTagName("div")[0].innerHTML = "";
document.querySelector(".output").innerHTML = "";

let tal1 = parseInt(document.getElementById("tal1").value);
let tal2 = parseInt(document.getElementById("tal2").value);
let finalValue = 0;

while(tal1 < tal2 + 1){
if (tal1 * -1 > tal2) break;

let isNegativeOutput = (tal1 < 0) ? document.getElementsByTagName("div")[0].innerHTML += tal1 : document.getElementsByTagName("div")[0].innerHTML += "+" + tal1;

finalValue += tal1;
tal1 *= -1;
let isNegative = (tal1 < 0) ? tal1 -= 1 : tal1 += 1;
}
document.querySelector(".output").innerHTML = "= " + finalValue;
}
</script>