0

I'm having difficulty in correcting the syntax error for image swap. I would appreciate if you can help me out as below?

function swap(i, s)
{
   var d = document.images;
   d ? d[i].src=s : null;
}
1

1 Answer 1

1

I think you want something like this

function swap(i, s) {
    var d = document.images;
    if (i >= 0 && i < d.length) {
        d[i].src = s;
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Much appreciated, Evin.
I made a slight mistake so I edited the question and fixed it, @Irishgirl

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.