Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write the code which would perform the following task using two images of your c

ID: 3800376 • Letter: W

Question

Write the code which would perform the following task using two images of your choosing:

Use a function to swap the positions of the images when the mouse is over either image. (Call the same function in the onmouseover event handler for both images. The function will load images in the appropriate positions.)

Swap the images back to their original positions when the mouse is moved off of the images (You can use the same function and pass different values with the parameters. This function will load both of the original images.)

Explanation / Answer

<img id="img1" src="http://placehold.it/300x300">

<img id="img2" src="http://placehold.it/200x200">

<script>

    var img1 = document.getElementById("img1");

    var img2 = document.getElementById("img2");

    var img1path = "http://placehold.it/300x300";

    var img2path = "http://placehold.it/200x200";

    function doFlip(isOn) {

        if (isOn) {

            img1.src = img2path;

            img2.src = img1path;

        } else {

            img1.src = img1path;

            img2.src = img2path;

        }

    }

</script>