473,394 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

JavaScript - beginners assistance: two arrays, Helps!

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
4 1423
improvcornartist
303 Expert 100+
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
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
GUMBO
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
16,027 Expert Mod 8TB
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

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

Similar topics

7
by: Tod Thames | last post by:
I am running SQL Server 7.0 and using a web interface. I would like for a user to be able to input multiple values into a single field with some sort of delimiter (such as a comma). I want to...
4
by: Drew | last post by:
I need to do some client-side scripting for my Intranet and was wondering if Jscript or Javascript would be better? Everyone here uses IE 5.0 +, so I need to make a decision... Thanks, Drew
13
by: Kevin | last post by:
Help! Why are none of these valid? var arrayName = new Array(); arrayName = new Array('alpha_val', 1); arrayName = ; I'm creating/writing the array on the server side from Perl, but I
22
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last...
2
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
104
by: Leszek | last post by:
Hi. Is it possible in javascript to operate on an array without knowing how mamy elements it has? What i want to do is sending an array to a script, and this script should add all values from...
41
by: Rene Nyffenegger | last post by:
Hello everyone. I am not fluent in JavaScript, so I might overlook the obvious. But in all other programming languages that I know and that have associative arrays, or hashes, the elements in...
43
by: Bill H | last post by:
25 years ago every computer came with some form of Basic interpreter so you could use yoru computer without having to buy more software. Is Javascript (teamed with HTML) set to become the new...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.