I have pasted my code below, please paste it into a JSP and tell me why it gives the error "Unterminated String Constant"

        <script language="javascript">
            function changeOn(object, objectId) {
                alert('in function');
                if (object == 'bookingsButton') {
                    alert('first if');
                    document.getElementById(objectId).src = 'Images/BookingsOn.png';
                } else if (object == 'detailsButton') {
                    alert('2nd if');
                    document.getElementById(objectId).src = 'Images/DetailsOn.png';
            function changeOff(object, objectId) {
                if (object == 'bookingsButton') {
                    document.getElementById(objectId).src = 'Images/Bookings.png';
                } else if (object == 'detailsButton'){
                    document.getElementById(objectId).src = 'Images/Details.png';
                    for (int i = 0; i < 2; i++) {
                    <a href="Bookings.jsp"><img src="Images/Bookings.png" id="bookings<%out.println("" + i);%>" onmouseover="changeOn('bookingsButton','bookings<%out.println("" + i);%>')" onmouseout="changeOff('bookingsButton','bookings<%out.println("" + i);%>')"/></a>
                    <a href="Details.jsp"><img src="Images/Details.png" id="details<%out.println("" + i);%>"/></a>
        <% }%>


The use of out.println() adds a newline character causing erroneous syntax of the generated output.
The generated html is,

<img src="Images/Bookings.png" id="bookings0
" onmouseover="changeOn('bookingsButton','bookings0
')" onmouseout="changeOff('bookingsButton','bookings0

There is a newline character after bookings0

Use out.print() instead. Which will generate html like,

<img src="Images/Bookings.png" id="bookings0" onmouseover="changeOn('bookingsButton','bookings0')" onmouseout="changeOff('bookingsButton','bookings0')"/>