...

View Full Version : Javascript coding problems - program not work



worldtraveller
11-15-2010, 03:37 AM
Hello all out there I am going to post this in 2 separate views.

I am working on an assignment from this link

http://books.google.ca/books?id=aG_T2aD ... MonthCell()&source=bl&ots=EJXyGF-tbI&sig=vbgqgua2uSaL6DWp0Rx_BYoZ0z8&hl=en&ei=9C7gTLmiAYaXnAeywLWRDw&sa=X&oi=book_result&ct=result&resnum=1&ved=0CBcQ6AEwAA#v=onepage&q=writeMonthCell()&f=false

if u scroll down to case 1
is what I am working on

included in the case are 2 other files as to the one i have to work on

i used all the proper steps and instructions and i think I have the correcting coding for my form

however my program still does not work

here is the exact code i am using
let me know if anyone sees any errors, as I am convinced i have it correct?

Here is my code:


<html>
<head>
<!--
New Perspectives on JavaScript
Tutorial 3
Case Problem 1

The Lighthouse
Author: John Res
Date: November 14 2010

Filename: clist.htm
Supporting files: lhouse.css, list.js, logo.jpg

-->
<title>The Lighthouse</title>
<link href="lhouse.css" rel="stylesheet" type="text/css" />
<script type"text/javascript" src"list.js"></script>
<script type="text/javascript">
function amountTotal() { // return sum of values to amount array
total=0;
for(var i=0; i<amount.length; i++) { // set variable to 0
total+=amount[i];
}
return total;
}
</script>
</head>

<body>

<div id="title">
<img src="logo.jpg" alt="The Lighthouse" />
The Lighthouse<br />
543 Oak Street<br />
Delphi, KY &nbsp;&nbsp;89011<br/>
(542) 555-7511
</div>

<div id="data_list">
<script type=”text/javascript”> // set up variables of rows and cellspaces
document.write(“<table border=’1′ rules=’rows’ cellspacing=’0′>”);
document.write(“<tr><th>Date</th><th>Amount</th><th>First Name</th>”);
document.write(“<th>Last Name</th><th>Address</th></tr>”);

for (i=0; i< amount.length; i++) { // create a loop in counter of variable starting at 0 and increase of 1 increments
if (i%2==0) document.write(“<tr>”);
else document.write(“<tr class=’yellowrow’>”); // have every row with a yellow background use a loop

document.write(“<td>”+date[i]+”</td>”);
document.write(“<td class=’amt’>”+amount[i]+”</td>”); // have values of the dates
document.write(“<td>”+firstName[i]+”</td>”);
document.write(“<td>”+lastName[i]+”</td>”);
document.write(“<td>”);
document.write(street[i]+”<br />”);
document.write(city[i]+”, “+state[i]+” “+zip[i]); // zip arrays for address
document.write(“</td>”);
document.write(“</tr>”);
}
document.write(“</table>”);
</script>

</div>

<div id="totals">
<script type=”text/javascript”> // use script elements in HTML
document.write(“<table border=’1′ cellspacing=’1′>”);
document.write(“<tr><th id=’sumTitle’ colspan=’2′>Summary</th></tr>”);
document.write(“<tr><th>Contributors</th>”);
document.write(“<td>”+amount.length+”</td></tr>”);
document.write(“<tr><th>Amount</th>”);
document.write(“<td>$”+amountTotal()+”</td></tr>”);
document.write(“</table>”);
</script>

</div>

</body>
</html>

thanks everyone

Logic Ali
11-15-2010, 04:17 AM
here is the exact code i am usingYour code contains word-processing characters. You must create your code using a text editor or convert it to plain text.

worldtraveller
11-15-2010, 04:35 AM
my code is word processing? how so

as i did the coding all on textwrangler which is totally for javascript etc?


Does all my lines seem wrong of what i typed? bad format? or what exactly did i go wrong?
thanks

Logic Ali
11-15-2010, 05:03 AM
my code is word processing? how so

as i did the coding all on textwrangler which is totally for javascript etc?


Does all my lines seem wrong of what i typed? bad format? or what exactly did i go wrong?
thanksThe double and single quote characters ( “ ” ’ ) are incorrect, they should be " and ' respectively. I'm not familiar with that editor, but it must have a way of fixing that.

Philip M
11-15-2010, 10:01 AM
You must have copied it from somewhere using copy and paste.

<script type=”text/javascript”> will simply not function.

When posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.


It is your responsibility to die() if necessary….. - PHP Manual

worldtraveller
11-15-2010, 12:11 PM
Textwrangler is the text editor for MAC computers.

For all my quotations

is it just my " and ' that seems to be wrong

or are all my actual structures incorrect as well?

give me an example of one line, as now i am so confused.

thanks

Philip M
11-15-2010, 12:16 PM
There are many instances of incorrect pattern quotes.

document.write(“<td>”+date[i]+”</td>”);

Put these right, then test you code again using your error console. You should not look to this forum just to identify syntax errors. Firebug will do that for you.

worldtraveller
11-16-2010, 04:15 AM
I am going over my notes and so far I am not successful on this. Nothing is working it seems.

What would be the proper way to type out this small portion of code such as for.

<title>The Lighthouse</title>
<link href="lhouse.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="list.js"></script>
<script type="text/javascript">
function amountTotal() { // return sum of values to amount array
total=0;
for(var i=0; i<amount.length; i++) { // set variable to 0
total+=amount[i];
}
return total;
}
</script>
</head>

<body>

thanks all.

Philip M
11-16-2010, 09:01 AM
One more time:-

When posting here please follow the posting guidelines and wrap your code in CODE tags. This means use the octothorpe or # button on the toolbar. You can (and should) edit your previous post.

You do not have any array named amount, so there is nothing to add up.

Passengers hit by cancelled trains. - Guildford News And Mail

worldtraveller
11-17-2010, 04:07 AM
ok all I went over my assignment again and worked on all my arrays and loops

now i made the program worse then it was before

here is all my coding now

i messed it all up
Here is all my code




<html>
<head>
<!--
New Perspectives on JavaScript
Tutorial 3
Case Problem 1

The Lighthouse
Author: Joh
Date: November 14 2010

Filename: clist.htm
Supporting files: lhouse.css, list.js, logo.jpg

-->
<title>The Lighthouse</title>
<link href="lhouse.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="list.js"></script>

<script type="text/javascript">

function amountTotal() {


<script type="text/javascript">

function amountTotal() {
var amountTotal=0;
var total=0;

for ( amountTotal=0;amountTotal<=0;i++)
var<=0; var=amountTotal+total )
{
document.write(i+ <"/br>" );
}
</script>



</script>
</head>


<body>

<div id="title">
<img src="logo.jpg" alt="The Lighthouse" />
The Lighthouse<br />
543 Oak Street<br />
Delphi, KY &nbsp;&nbsp;89011<br/>
(542) 555-7511
</div>

<div id="data_list">

<script type+"text/javascript" // set up variables of rows and cellspaces
document.write("<table border='1' rules='rows' cellspacing='0'>");
<tr>
document.write("<th>Date</th><th>Amount</th><th>First Name</th>");
document.write("<th>Last Name</th><th>Address</th>");


<script language="javascript">

for (counter=0; amountarray<=; counter->amount array+1);
{
document.write("<tr><td>"+amountarray+"</td><td>"
+(counter+1)+"</td></tr>");
}
</script>
</table>

else document.write("<tr class=’yellowrow’>”);
<td>date</td>
document.write("<td>”+date+”</td>”);
document.write("<td class='amt'>”+amount[i]+"</td>");
document.write("<td>”+firstName[i]+”</td>”);
document.write("<td>”+lastName[i]+”</td>”);
document.write("<td>”);
document.write(street[i]+"<br />”);
document.write(city[i]+", “+state[i]+” “+zip[i]);
document.write("</td>”);
document.write("</tr>”);
}
document.write(“</table>”);
</script>

</div>

<div id="totals">
<script type="text/javascript”>
document.write("<table border=’1′ cellspacing=’1′>”);
document.write"<tr><th> id=’sumTitle’ colspan=’2′>Summary</th></tr>”);
document.write("<th>Contributors</th>”);

document.write("<td>contributions</td>");
document.write("<td><tr>”+amount.length+”</td></tr>”);
document.write("<th>Amount</th>”);
document.write("<tr><td>$”+amountTotal()+”</td></tr>”);
document.write("</table>”);
</script>

</div>

</body>
</html>


thanks all for taking the time to look it all over

Philip M
11-17-2010, 09:33 AM
There are still numerous cases of incorrect quotes in your code. Examples:-

document.write(city[i]+", “+state[i]+” “+zip[i]);
document.write("</td>”);
document.write("</tr>”);
}
document.write(“</table>”);

You must get rid of all of those. Use global find and replace in your editor.
Then use your error console.
Until you do that nothing more can be done for you.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum