+ Reply to Thread
Results 1 to 1 of 1
  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    1

    Javascript code correct?

     
    I'm trying to figure out this question that was assigned to me, as I haven't done much javascript before I'm not sure if this is correct. If anybody could help it would be greatly appreciated.

    The question is as follows:

    You are provided with a string array called country that contains the name of every country that the Ski Club visits. For example one element of this array might be as follows:

    country[0] = "Austria"

    Another array called villages contains strings with information on village names and altitude in a particular country. For example:

    villages[0] = "Austria:Seefield 850m*";

    Write a JavaScript function snowReport(countryIndex) that will use the arrays provided to write a report of all villages that include a given country. The function will be passed an integer representing the index of an element of the country array.

    A match is found if the country appears in a string (Hint use appropriate JavaScript function to evaluate if a country name is contained in a village string.)

    All matching villages should be displayed. Output should be displayed in the villages div element you defined in part (a). Output is shown for a search for Austria in Figure 1b.



    <script type="text/javascript">

    function makeArray() {
    var country = new Array(5);
    country[0] = "Austria";
    country[1] = "Canada";
    country[2] = "France";
    country[3] = "Germany";
    country[4] = "Switzerland";
    return country;

    var villages = new Array(2);
    villages[0] = "Austria:Seefield 850m*";
    villages[1] = "Austria:Ellam 100m";
    return villages;
    }

    function snowReport(countryIndex){
    var string = "";
    for (var i = 0; i < countryIndex.length; i++){
    str += countryIndex[i] + " ";
    }
    return str;
    }
    </script>
    </head>
    <body>
    <script>
    var x = makeArray();
    document.write(snowReport(x));
    </script>

    </body>
    </html>



    Many thanks!
    Last edited by omccann0991; May 7th, 2011 at 10:51 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Help with Javascript
    By me4u2nv in forum Webmastering and Programming
    Replies: 0
    Last Post: January 22nd, 2009, 07:15 PM
  2. Help with javascript
    By justawebbie in forum Webmastering and Programming
    Replies: 3
    Last Post: December 6th, 2008, 10:16 PM
  3. Javascript
    By presence06 in forum General Tech Discussion
    Replies: 1
    Last Post: April 3rd, 2006, 02:08 PM
  4. Need Some Javascript Help!
    By Blazer06 in forum Webmastering and Programming
    Replies: 1
    Last Post: January 2nd, 2005, 02:56 AM
  5. Javascript help
    By raven7647 in forum Webmastering and Programming
    Replies: 2
    Last Post: August 6th, 2002, 08:41 PM

Tags for this Thread

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Recommended Sites: ResellerRatings Store Reviews