1

It seems like I followed the directions completely in my assignment powerpoint, I checked if I was using each function right, tripple checked my spelling, and I have no idea why it wont work, I'm very new to javascript, I tried debugging it from top to bottom, however it seems something is making my script not work, or I am doing something wrong all together. What am I doing wrong with my code?

<html xmlns="http://www.w3.org/1999/xhtml">

<HEAD>
<TITLE>Rollover Banner </TITLE>
<SCRIPT LANGUAGE="JavaScript">

    <!-- VARIABLE DECLARATION -->

    if (document.images) 
    {
       var photos = new Array (“images1/nj1.jpg”,”images1/nj2.jpg”,”images1/dice1.jpg”);
       var photoURLs = new Array (“msn.com”,”imdb.com”,”tv.com”);
    }
    var i = 0;

    function newLocation()
    {
        document.location.href="http://www." + photoURLs[i];
    }
    function rotate()
    {
        i = Math.floor(Math.random()*3);
        document.banner.src = photos[i];
        document.write(i); //doesnt do anything
        setTimeout("rotate()", 1000);
    }

</SCRIPT>
</HEAD> 

<BODY >


    <a href="javascript:newLocation()"> <!--doesnt direct to anything -->
       <img src="images1/nj2.jpg" name="banner"> <!--loads -->
    </a>

    <SCRIPT language="Javascript">

        rotate();
    </SCRIPT>

</BODY>
</HTML>
J L
  • 367
  • 5
  • 11
  • how do you check those? (very new sorry) – J L Oct 11 '14 at 07:46
  • HOLY CRUD I fixed it by clicking view source, and sure enough i was using copy pasted quotes >.< then i took out the doc.write(i) and its working :| 30 minutes past the due date of course >.< need to learn how to ask for help easier.. – J L Oct 11 '14 at 07:48
  • 1
    In case you still want to know how to check errors in console: Chrome: Ctrl + Shift + I, press the console tab. IE: http://stackoverflow.com/a/2656884/3492895, Firefox: "select "Web Console" from the Web Developer submenu in the Firefox Menu (or Tools menu if you display the menu bar or are on Mac OS X), or by pressing its Control-Shift-K (Command-Option-K on the Mac) keyboard shortcut." - https://developer.mozilla.org/en-US/docs/Tools/Web_Console – Winestone Oct 11 '14 at 07:52

1 Answers1

1

Make sure that you are not using smart quotes in your arrays. Try retyping the " character, even if it looks normal.

Smart quotes are a very annoying issue for developers alike.

Addition: The find and replace feature is very helpful with this.

  • 1
    Sorry you didn't get the answer faster! Always check for smart quotes in the code, especially when coming across little issues like this. Good Luck! – ACarlson1994 Oct 11 '14 at 07:54