Thread: Javascript Help?
-
May 7th, 2011, 10:33 AM #1Junior 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
-
Help with Javascript
By me4u2nv in forum Webmastering and ProgrammingReplies: 0Last Post: January 22nd, 2009, 07:15 PM -
Help with javascript
By justawebbie in forum Webmastering and ProgrammingReplies: 3Last Post: December 6th, 2008, 10:16 PM -
Javascript
By presence06 in forum General Tech DiscussionReplies: 1Last Post: April 3rd, 2006, 02:08 PM -
Need Some Javascript Help!
By Blazer06 in forum Webmastering and ProgrammingReplies: 1Last Post: January 2nd, 2005, 02:56 AM -
Javascript help
By raven7647 in forum Webmastering and ProgrammingReplies: 2Last Post: August 6th, 2002, 08:41 PM



LinkBack URL
About LinkBacks



Reply With Quote

Good Morning friends.. You have to watch following shows and movies on daily basis. Warehouse 13 Season 4 Episode 14 Bates Motel Episode 10 Regular Show Season 4 Episode 27 The Secret Life of...
Watch free online NOW