dcsimg
www.webdeveloper.com
Results 1 to 2 of 2

Thread: Help with Array

  1. #1
    Join Date
    Mar 2006
    Posts
    1

    Help with Array

    hello, i'm not very good with javascript and i need help with an assignment.. if anyone can help me, i would appreciate it. I need to create a program that creates an array, then the user searches for a number and it will display how many times its been found, i also need to sort the array and remove the repeated elements (ie two 6's is only one 6)

    here is what i have so far:

    <html>
    <head>
    <script type="text/javascript">
    <!--

    var a,b=0,c,arr=new Array(Math.floor(5+Math.random()*16));
    //array is random between 5-20
    init();
    a = window.prompt("enter number to find binary equivelant","0");


    printArray();
    c=arr.sort();

    document.write("<table border=1><tr><td>sorted</td><td>"+c);

    function init() {
    for(var i=0; i<arr.length; i++)
    arr[i] = Math.floor(1+Math.random()*21);


    }
    //randomize [i]

    function printArray() {
    document.writeln("<table border=1 cellspacing=1><tr><td>original</td>");
    for (var i=0; i<arr.length; i++) {
    if (arr[i]==a)
    {
    b=b+1
    }
    document.writeln("<td>"+arr[i]+"</td>");
    }

    }

    document.writeln(b);

    // -->
    </script>
    <title>Lab 9 Part 2: Algorithms</title>
    </head>
    <body>

    </body>
    </html>

  2. #2
    Join Date
    May 2003
    Location
    O!
    Posts
    200
    Quote Originally Posted by spikey
    hello, i'm not very good with javascript and i need help with an assignment.. if anyone can help me, i would appreciate it. I need to create a program that creates an array, then the user searches for a number and it will display how many times its been found, i also need to sort the array and remove the repeated elements (ie two 6's is only one 6)
    If I understand you correctly, it looks like any number that the user searches for will occur either 0 or 1 time (since you are removing repeated numbers). Is your description correctly stated?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles