473,657 Members | 2,355 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

JavaScript - beginners assistance: two arrays, Helps!

4 New Member
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="JavaS cript">
<!-- 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="JavaS cript">
<!-- Start hiding from non-JavaScript browser
//Insert the titles of the nightly specials below
var Today=new Date();
var WeekDay=Today.g etDay();
var SpecialName=Dis hName(WeekDay);
document.write( SpecialName);
//Stop hiding -->
</script>

<dd>
<script language="JavaS cript">
<!--- Start hiding from non-JavaScript browser
//Insert the descriptions of the nightly specials below
var Today=new Date();
var WeekDay=Today.g etDay();
var SpecialDesc=Dis hDesc(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 1434
improvcornartist
303 Recognized Expert Contributor
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
pmactdot
4 New Member
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 New Member
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 Recognized Expert Moderator MVP
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
1378
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 pass this field into a Stored Procedure and have the stored procedure use the data to generate the resutls. Example: Web page would ask for ID number into a field called IDNum. User could input one or many ID numbers separated by a comma or...
4
1519
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
2509
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
4604
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 month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
2
5212
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 down to a very simple test case which can be cut-n-pasted into a .html file and viewed in a browser: ============================================================================
136
9305
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 code was littered with document.all and eval, for example, and I wanted to create a practical list of best practices that they could easily put to use. The above URL is version 1.0 (draft) that resulted. IMO, it is not a replacement for the FAQ,...
104
16929
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 that array Could you show me a little example how to do this? Thanks.
41
4927
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 the hash are alphabetically sorted if the key happens to be alpha numeric. Which I believe makes sense because it allows for fast lookup of a key.
43
2380
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 Basic, where anyone with a computer can start writing code without having to purchase any expensive languages? Bill H
0
8312
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8827
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8732
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8606
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7337
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6169
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
2732
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1959
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1622
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.