By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,212 Members | 2,209 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,212 IT Pros & Developers. It's quick & easy.

JavaScript - beginners assistance: two arrays, Helps!

P: 4
Hi,

I'm looking for some assistance on a case study...I have two arrays <head>: one for daily special dish name, second for the daily dish description, then I have two document.write: a daily special dish name <dt>, second to write the daily dish description <dd>. DishName works, just can't figure out the description. The <body> code was provided, I only need to get (and understand) the two arrays and two document.write scripts working. I've just started JavaScript, so please be gentle :-)

[HTML]<html>
<head>
<title>Kelsey's Dinner Menu</title>

<script language="JavaScript">
<!-- Hide from non-JavaScript browsers[/HTML]
Expand|Select|Wrap|Line Numbers
  1. function DishName (Day) {
  2.     var DName=new Array();
  3.     DName[0]="Chicken Burrito Amigo";
  4.     DName[1]="Chicken Tajine";
  5.     DName[2]="Pizza Bella";
  6.     DName[3]="Salmon Filet";
  7.     DName[4]="Greek-style Shrimp";
  8.     DName[5]="All-you-can-eat-fish";
  9.     DName[6]="Prime Rib";
  10.     return DName[Day];
  11. }
  12.  
  13. function DishDesc (Day) {
  14.     var DDesc=new Array();
  15.     DName[0]="Chicken with mushrooms, onions, and Monterey Jack cheese wrapped in a flour tortilla. 9.95";
  16.     DName[1]="Chicken baked with garlic, olives, capers, and prunes 8.95";
  17.     DName[2]="Large pizza with pesto, goat cheese, onions, and mozzeralla cheese 8.95";
  18.     DName[3]="Grilled Salmon with spicy curry sauce and baked patato. 9.95";
  19.     DName[4]="Shrimp, feta cheese, and tomatoes simmered in basil and garlic. 9.95";
  20.     DName[5]="Deep-fired cod with baked patato and rolls. 9.95";
  21.     DName[6]="12 oz. cut with baked patato, rolls, and dinner salad. 12.95";
  22.     return DDesc[Day];
  23. }
  24. // Stop hiding -->
  25.  
[HTML]</script>

<style>
body {}
h3 {color:blue;}
dt {font-weight:bold; color:green;}
</style>
</head>
<body>
<center><img src="dinner.jpg">
<h5><span style="font-size:x-large; color:green">
Dinner Menu</span><br>
Served 4:00 p.m. - 10:00 p.m.</h5><hr></center>
<dl>
<h3>Today's Special</h3>

<dt>
<script language="JavaScript">
<!-- Start hiding from non-JavaScript browser
//Insert the titles of the nightly specials below
var Today=new Date();
var WeekDay=Today.getDay();
var SpecialName=DishName(WeekDay);
document.write(SpecialName);
//Stop hiding -->
</script>

<dd>
<script language="JavaScript">
<!--- Start hiding from non-JavaScript browser
//Insert the descriptions of the nightly specials below
var Today=new Date();
var WeekDay=Today.getDay();
var SpecialDesc=DishDesc(WeekDay);
document.write(SpecialDesc);
//Stop hiding -->
</script>

<dt><hr>Cajun Meatloaf
<dd>Lean beef served with Kelsey's Southwestern mashed potatoes. 8.95
<dt>Chicken Marsala
<dd>Plump chicken breasts sauteed with tomatoes, mushrooms, &amp; artichoke hearts
with a splash of Marsala wine. 8.95
<dt>Pecan Crusted Whitefish
<dd>Quickly seared fish &amp; fresh mushrooms served with pineapple chutney. 10.95
<dt>Thai Stir Fry
<dd>Fresh crisp vegetables quickly sauteed, tossed with Kelsey's spicy
peanut sauce, served over rice. 8.95
<dt>Jambalaya
<dd>Plump shrimp, chicken, &amp; spicy sausage slowly simmered with tomatoes and
rice. 9.95
<dt>Wild Rice Stuffed Squash
<dd>Winter squash stuffed with fresh harvest vegetables &amp; pecan rice, served
with pineapple chutney &amp; melted Monterey Jack. 8.95
<dt>Cuban Beans &amp; Rice
<dd>Black turtle beans simmered with carrots, tomatoes, &amp; green peppers,
served over rice with spicy salsa, guacamole, &amp; flour tortillas. 7.95
</dl>
</body>
</html>[/HTML]


Cheers,
pmactdot
Dec 29 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 100+
P: 303
Expand|Select|Wrap|Line Numbers
  1. function DishDesc (Day) {
  2.     var DDesc=new Array();
  3.     DName[0]="Chicken with mushrooms, onions, and Monterey Jack cheese wrapped in a flour tortilla. 9.95";
  4.     DName[1]="Chicken baked with garlic, olives, capers, and prunes 8.95";
  5.     DName[2]="Large pizza with pesto, goat cheese, onions, and mozzeralla cheese 8.95";
  6.     DName[3]="Grilled Salmon with spicy curry sauce and baked patato. 9.95";
  7.     DName[4]="Shrimp, feta cheese, and tomatoes simmered in basil and garlic. 9.95";
  8.     DName[5]="Deep-fired cod with baked patato and rolls. 9.95";
  9.     DName[6]="12 oz. cut with baked patato, rolls, and dinner salad. 12.95";
  10.     return DDesc[Day];
  11. }
Welcome to TheScripts.

The error is in the DishDesc function. It defines a new array, DDesc, but attempts to create the descriptions in a DName array, which does not exist. All of those DName references within the DishDesc function need to be DDesc. That will fix the problem. One good tool for finding mistakes like this is Firefox's Error Console. It will often specify what the error is and where it is in the code. Also, in the future, please use code tags when posting code. They make the code look much prettier and easier to read. Thanks.
Dec 29 '07 #2

P: 4
Welcome to TheScripts.

The error is in the DishDesc function. It defines a new array, DDesc, but attempts to create the descriptions in a DName array, which does not exist. All of those DName references within the DishDesc function need to be DDesc. That will fix the problem. One good tool for finding mistakes like this is Firefox's Error Console. It will often specify what the error is and where it is in the code. Also, in the future, please use code tags when posting code. They make the code look much prettier and easier to read. Thanks.


Brilliant! Thanks for the clarification and tips. Greatly appreciated!
Dec 31 '07 #3

P: 1
Welcome to TheScripts.

The error is in the DishDesc function. It defines a new array, DDesc, but attempts to create the descriptions in a DName array, which does not exist. All of those DName references within the DishDesc function need to be DDesc. That will fix the problem. One good tool for finding mistakes like this is Firefox's Error Console. It will often specify what the error is and where it is in the code. Also, in the future, please use code tags when posting code. They make the code look much prettier and easier to read. Thanks.

i STILL DONT" GET IT CAN SOMEONE HELPME PLEASE [EDIT]
Mar 22 '08 #4

acoder
Expert Mod 15k+
P: 16,027
i STILL DONT" GET IT CAN SOMEONE HELPME PLEASE
What's not working? Difficult to tell if you don't post code.

PS. I think you left your caps lock key on.
Mar 23 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.