Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 3 of 3
  1. #1
    Junior Member Corps_Dryke's Avatar
    Join Date
    Sep 2007
    Posts
    1
    Member #
    15780
    Hi, I am kinda new to the Jvavscript wourld. I have a project for school due tomorrow and as many times and ways i have tried to write this jave script I am unable to get it to run. I typed everything the way I was showed and how my book told me to. It may just be syntax but I dont think it is. Below is the script I am working with, If anyone could help me out, that would be awsome.
    Thanks,
    Corps_Dryke

    HTML Code:
    <script type="text/javascript">
            <!--Begin
            /* Created by: Robert McCoy::
             *
             *This script uses hue rotation in the<script type="text/javascript">
            <!--Begin following manner:
             *hue=0 is red (#FF0000)
             *hue=60 is yellow (#FFFF00)
             *hue=120 is green (#00FF00)
             *hue=180 is cyan (#00FFFF)
             *hue=240 is blue (#0000FF)
             *hue=300 is magenta (#FF00FF)
             *hue=360 is hue=0 (#FF0000)
             *
             *Notes on this script
             *
             *This script should function in any browser that supports document . getElementById
             *It has been tested in Netscape7, Mozilla Firefox1.0, and Internet Explorer 7
             *
             *Accessibility
             *
             */
            
            /*
             *splits par.firstChild.data into 1 span for each letter
             *span - HTML element contining a text node as the only element
             */
            function toSpans (span) (
             var str=span.firstChild.data;
             var a=str.length;
             span.removeChild (span.firstChild);
             for (var i=0; i<a i++) (
               var theSpan=document.createrElement("SPAN");
               theSpan.appendChild (document.createTextNode (str.charAt (i)));
               span.appendChild (theSpan);
       )
     )
     
     /*
      * creates a rainbowspan object
      * whose letters will be colored [deg] degrees of hue
      *ARGUMENTS
      *   span - HTML element to apply the effect to (text only, no HTML)
      *   hue - what degree of hue to start at (0-359)
      *   deg - how many hue degrees should be traversed from beginning to end of the string (360 => faster)
      *   brt - brightness (0-255, 0 => black, 255 => full color)
      *   spd - how amny ms between moveRainbow calls (less => faster)
      *   hspd - how many hue degrees to move every time moveRainbow is called (0-359, closer to 180 => faster)
      */
     function RainbowSpan (span, hue, deg, brt, spd, hspd) (
               this.deg=(deg==null?360:Math.abs(deg);
               this.hue=(hue==null?0:math.abs(hue)%360);
               this.hspd=com(hspd=null?3:Math.abs(hspd)%360)
               this.length=span.firstChild.data.length;com
               this.span=span;
               this.speed= (spd==null?50:Math.abs(spd));
               this.hInc=this.deg/this.length;
               this.brt=(brt==null?255:Math.abs(brt)%256);
               this.timer-null;
               toSpans(span);
               this.moveRainbow();
    )
    
    /*
     *sets the colors of the children of [this] as a hue-rotating rainbow at this.hue;
     *requires something to manage ch externally
     *I had to make the RainbowSpan class because M$IE wouldn't let me attach prototype to [Object]
     */
    RainbowSpan.prototype.moveRainbow = function() (
            if (this.hue>359) this.hue-=360;
            var color;
            var b=this.brt
            var a=this.length;
            var h=this.hue;
            
            for(var i=0; i<a; i++) {
                
                if (h>359) h-=360
                if(h<60) { color=Math.floor((h)/60)*b) ; red=b;grn=color;blu=0; }
                else if(h<120) { color=Math.floor(((h-60)/ 60)*b); red=b-color;grn=b;blu=0; }
                else if(h<180) { color=Math.floor(((h-120)/ 60)*b); red=0;grn=b;blu=color; }
                else if(h<240) { color=Math.floor(((h-180)/ 60)*b); red=0;grn=b-color;blu=b; }
                else if(h<300) { color=Math.floor(((h-240)/ 60)*b); red=color;grn=0;blu=b; }
                else { color=Math.floor(((h-300)/ 60)*b); red=b;grn=0;blu=b-color }
                
                h+=this.hInc
                        
                  this.spn.childNodes[i].style.color="rgb ("+red+", "+grn", "+blu")";
            }
            this.hue+=this.hspd;
            
    }
    // End -->
    </script>
            
                  
    <div align="center">
       <h3 id="r1"> Welcome to the would of Java</h3>
            </div>
            <script type="text/javascript"><d
            var r1=document.getElementById("r1"); //get span to apply rainbow
    var myRainbowSpan=new RainbowSpan(r1, 0, 360, 255, 50, 18); //apply static rainbow effect
    myRainbowSpan.timer=window.setInterval("myRainbowSpan.moveRainbow()", myRainbowSpan.speed);
    </script>
            <br><br><br><br>
            <div align="center">
            <p id="r2"> If you don't see a nifty moving rainbow above, then your broser doesn't understand my JavaScript.</p>
            </dive>
            <script type="text/Javascript">
            var r2=document.getElementById("r2"); //get span to apply rainbow
            var myRainbowSpan2=new RainbowSpan (r2, 0, 360, 255, 50, 348); //apply static rainbow effect
            myRainbowSpan2.timer=window.setIdnterval("myRainbowSpan2.moveRainbow()", myRainbowSpan2.speed);
            </script>

  2.  

  3. #2
    Senior Member -chris-'s Avatar
    Join Date
    Apr 2006
    Location
    SK
    Posts
    1,205
    Member #
    13102
    This probably won't affect the JS, but should be fixed.
    Quote Originally Posted by Corps_Dryke
    <p id="r2"> If you don't see a nifty moving rainbow above, then your broser doesn't understand my JavaScript.</p>
    </dive>
    <script type="text/Javascript">
    should be:
    Code:
    <p id="r2"> If you don't see a nifty moving rainbow above, then your browser doesn't understand my JavaScript.</p>
            </div>
            <script type="text/Javascript">
    Portfolio | Blog | Twitter

    Was my post, or someone elses, helpful? Click the thumbs up to let everyone know!

  4. #3
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    You seem to have some ()s where you should have {}s... eg...

    function RainbowSpan (span, hue, deg, brt, spd, hspd) ( <-- here
    this.deg=(deg==null?360:Math.abs(deg);
    this.hue=(hue==null?0:math.abs(hue)%360);
    this.hspd=com(hspd=null?3:Math.abs(hspd)%360)
    this.length=span.firstChild.data.length;com
    this.span=span;
    this.speed= (spd==null?50:Math.abs(spd));
    this.hInc=this.deg/this.length;
    this.brt=(brt==null?255:Math.abs(brt)%256);
    this.timer-null;
    toSpans(span);
    this.moveRainbow();
    ) <-- here
    ...and in many of the other definitions etc...

    See if this helps...

    http://jslint.com/

    Sean

    Sean


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:36 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com