Q:

JS change image if/else

Im trying to change image when function ends. In IF image should change, and in else, image stays the same.
html
    <img class="owner" id="regina" src="img/uk-profile.jpg" alt="Great Britain">
  <p class="fort"><b>Fort: </b><span  id="wall">1000</span></p>

What i have tried in JS
function finish(){
    var f = document.getElementById('wall');

    if (f>-1) {
        alert("Battle has been won, you now control the region!");
        var g = document.getElementById('regina').src = "img/us-profile";

    }

     else {
        alert("Battle has been lost!");

     }
}

A:

When you use
var f = document.getElementById('wall');

In f you have the element not the value of the element, do the following: use .innerHTML to get the value and convert it to int, then you can check if (f > -1)
var f = parseInt(document.getElementById('wall').innerHTML);

function finish() {
  var f = parseInt(document.getElementById('wall').innerHTML);
  if (f > -1) {
    alert("Battle has been won, you now control the region!");
    var g = document.getElementById('regina').src = "http://www.newseum.org/wp-content/uploads/2015/02/xwinner.jpg.pagespeed.ic.iQ7m1XtFLg.jpg";

  } else {
    alert("Battle has been lost!");


  }
}

finish();
<img class="owner" id="regina" src="img/uk-profile.jpg" alt="Great Britain">
<p class="fort"><b>Fort: </b><span id="wall">1000</span></p>

