Q:

Javascript equality statement

So, I'm new to Javascript.  In my code I have an image object that is declared like so:
        <img src="me.png" id="changepic" alt="That's me!">

In my scripting code, I want to write a boolean statement that returns true when the src is "me.png" as it is in the picture and returns false if it is NOT "me.png".  This boolean statement is located within the conditions of the if statement below:
function changeImage() {
    if (document.getElementById("changepic").src === "me.png"){
        document.getElementById("changepic").setAttribute("src", "me2.png");
    }
}

I assigned the function changeImage to a button.  The code for the button is written below:
<button type="button" onclick="changeImage()">Change Image</button>

For some reason, the boolean statement inside of the if statement always returns false, although the src value of the Element really is "me.png."  I figured that this is a problem with how I'm writing the equality statement, but I don't know how to write an equality statement in javascript that would return true if the src value is "me.png" and return false if the src value is "me2.png".  Any takers?

A:

Change:
if (document.getElementById("changepic").src === "me.png"){

To:
if (document.getElementById("changepic").src.match(/me\.png$/)){

as .src will typically contain a full path to the image even though you don't specify it in the HTML.

