Results 1 to 7 of 7

Thread: Help with JavaScript please!

  1. #1
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Help with JavaScript please!

    Hi i am having trouble with javascript i have only just started learning it and need some help with a program i am creating. if you think u can help please let me know

    pjacko@gmail.com

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    if you think u can help please let me know

    pjacko@gmail.com
    If you can't be bothered to watch the thread, we can't be bothered to help you There's even a Subscribe to this Thread option.

    Some information about what you're actually trying to do would be nice, too.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default java

    hi sorry i am new to this

    I am trying to create a program that will ask a user for 4 different lengths and widths of a rectangle and to store the data in an array and output results

    i have just started learning java script. does anybody know about arrays

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <html>
    <head>
    <title>A</title>
    
    <style type="text/css">
    .rect {
      background-color: white;
      border: 1px solid gray;
      color: gray;
    }
    </style>
    
    <script type="text/javascript">
    function Rectangle(l, w, x, y) {
      this.length = l;
      this.width = w;
      this.area = l * w;
      this.x = x || Math.floor(Math.random() * 640);
      this.y = y || Math.floor(Math.random() * 480);
      this.dragging = false;
      this.id = Rectangle.currentID++;
    }
    
    Rectangle.prototype.move = function(x, y) {
      this.x = x;
      this.y = y;
    };
    
    Rectangle.prototype.draw = function() {
      var first = !this.element;
      if(first) {
        this.colour = (function() {
          var light = [];
          for(var i=0;i<3;i++)
            light.push(Math.floor(Math.random() * 256).toString(16));
          return "#" + light.join("");
        })();
        this.element = document.createElement("div");
        this.element.rect = this;
        this.element.style.backgroundColor = this.colour;
        this.paragraph = document.createElement("p");
        this.paragraph.style.top = "47%";
        this.paragraph.style.position = "relative";
        this.paragraph.style.textAlign = "center";
        this.element.appendChild(this.paragraph);
        this.info = document.createTextNode("");
        this.paragraph.appendChild(this.info);
        this.paragraph.appendChild(document.createElement("sup")).appendChild(document.createTextNode("2"));
        this.element.onclick = function() {
          this.rect.remove();
        };
      }
      this.info.nodeValue = this.length + "cm x " + this.width + "cm = " + this.area + "cm";
      this.element.style.position = "absolute";
      this.element.style.width = this.width + "cm";
      this.element.style.height = this.length + "cm";
      this.element.style.top = this.y + "px";
      this.element.style.left = this.x + "px";
      this.element.className = "rect";
      this.element.id = "rect" + this.id;
      if(first) document.body.appendChild(this.element);
    };
    
    Rectangle.prototype.remove = function() {
      this.paragraph.removeChild(this.info);
      delete this.info;
      this.element.removeChild(this.paragraph);
      delete this.paragraph;
      document.body.removeChild(this.element);
      delete this.element;
      delete this;
    }
    
    Rectangle.prototype.resize = function(l, w) {
      this.length = l;
      this.width = w;
      this.area = l * w;
    };
    
    Rectangle.currentID = 0;
    
    Rectangle.allRectangles = [];
    
    Rectangle.create = function() {
      var l = "", w = "";
      while(isNaN(parseFloat(l))) {
        if(l) window.alert(l + " is not a valid length.");
        l = window.prompt("Please enter the length of rectangle in centimeters:");
      }
      while(isNaN(parseFloat(w))) {
        if(w) window.alert(w + " is not a valid width.");
        w = window.prompt("Please enter the width of rectangle in centimeters:");
      }
      var r = new Rectangle(l, w);
      rects.push(r);
      r.draw();
      return r;
    };
    
    var rects = [];
    
    </script>
    </head>
    <body>
      <input type="button" onclick="Rectangle.create();" value="Create Rectangle">
    </body>
    </html>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Jun 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default thanks

    thank you very much. this code is a little to advance for me , is it possible i could email you some code i am working on

    cheers

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Not at the moment, I'm afraid... my web host has just shut down, so I currently have no email. I'll sort it out at some point.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Jun 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    a good place to help the beginner learn about javascript and a dozon other web programs is http://www.w3schools.com

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •