my code just stops

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • greenflame

    #1

    my code just stops

    I have a script and I ran it and it just seems to stop. The reason I
    say so is that the script does not get to the second alert. OK here it
    is:

    function show(input) {
    if (input.length == 1) {
    for (i=0;i<input[0].length;i++) {
    document.write( input[0][i]);
    }
    document.write( "<br>");
    } else {
    for (i=0;i<input.le ngth;i++) {
    for (j=0;j<input[0].length;j++) {
    document.write( input[i][j]);
    }
    document.write( "<br>");
    }
    }
    }
    function squareroot(inpu t) {
    output = copy2darr(input );
    alert(output.jo in("\n"));
    top = new Array(output[0].length);
    alert(output.jo in("\n")); // This is the alert it never gets to
    for (var i=0;i<output[0].length;i++) {
    top[i] = "—";
    }
    alert(top);
    n = output.unshift( top);
    alert(output.jo in("\n"));
    for (var i=0;i<output.le ngth;i++) {
    if (i == 0) {
    n = output[i].unshift("┌");
    } else {
    n = output[i].unshift("│");
    }
    }
    for (var i=0;i<output.le ngth;i++) {
    if (i != output.length-1) {
    n = output[i].unshift(" ");
    } else {
    n = output[i].unshift("\\");
    }
    }
    return output;
    }
    document.write( "long hyphen: —<br>leftmo st peice:
    ┌<br>right most peice: ┐<br>talle r bar: │<br>squar e
    root symbol: √<br><br>" );
    arr = [
    [" ","5"," "," "," "," "],
    ["x"," "," ","+"," ","x"]];
    show(arr);
    show(squareroot (arr));

  • Lasse Reichstein Nielsen

    #2
    Re: my code just stops

    "greenflame " <alikakakhel@ya hoo.com> writes:
    [color=blue]
    > I have a script and I ran it and it just seems to stop. The reason I
    > say so is that the script does not get to the second alert. OK here it
    > is:[/color]
    [color=blue]
    > function squareroot(inpu t) {
    > output = copy2darr(input );
    > alert(output.jo in("\n"));
    > top = new Array(output[0].length);[/color]

    Here you are assigning to the global variable "top". It already exists
    (window.top) and is a reference to the outermost frame in a set of
    frames, or just the page itself if no frames are involved. In, at least,
    IE, the global variable "top" is not writable, and you get an error trying.

    Generally, you should make all your variables local:
    var top = new Array(output[0].length);
    i.e., declare the variable with "var <variablename>" .
    [color=blue]
    > alert(output.jo in("\n")); // This is the alert it never gets to[/color]


    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • greenflame

      #3
      Re: my code just stops

      ok This seemed to work. Thanks

      Comment

      Working...