Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 3rd, 2007, 4:12 PM   #1
tromba
Newbie
 
Join Date: Sep 2006
Posts: 12
Rep Power: 0 tromba is on a distinguished road
Need help with solution

I'm teaching a class in basic computer skills and we're doing a little bit in programming using javascript. In most cases I can find the student's errors with little problems (I'm not a programmer and haven't done very much in javascript). However, I've gotten stumped on this one. In a previous spreadsheet project, students made an invoice for selling ice cream. I've had them put this online in javascript.

I've put her most recent edition here on the class website here.

I have the students put alerts in so they can see that their variables work right, and this student seems to do fine until the TOTAL button. I can't find an error there, so I'm guessing it's somewhere else, but I sure can't locate it.

Any suggestions? I need to look smart and be able to tell the students what they did wrong!!!!

Thanks.
tromba is offline   Reply With Quote
Old May 3rd, 2007, 5:04 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You wouldn't happen to be 'her', would you? Just curious about the lapse.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old May 3rd, 2007, 5:23 PM   #3
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Quote:
Originally Posted by DaWei View Post
You wouldn't happen to be 'her', would you? Just curious about the lapse.
I doubt it, especially given this: http://www.programmingforums.org/for...-to-print.html
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old May 3rd, 2007, 6:06 PM   #4
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
if (icecream == "fudge" || icecream == "rum" || icecream = "apple")
if (gallons == 5)s
You might want to check out JSLint.
titaniumdecoy is offline   Reply With Quote
Old May 4th, 2007, 8:49 AM   #5
tromba
Newbie
 
Join Date: Sep 2006
Posts: 12
Rep Power: 0 tromba is on a distinguished road
Nope. I'm not her. Her actual work is under her name on a different server. If you back up a directory from the link above, this is the class website where I post assignments and that type of thing. There isn't student access to that machine!!

We don't offer a computer science major here, so we don't have any programmers around. My background is entirely in music, and I got this course because I was available and I wanted to do it. When I did it for the first time, I thought the hardest part would be finding programming errors.... I learned JavaScript from the book like the students, but I kept going over it until I understood it all (unlike the students who skim it over and say "huh?".)

But as it turned out last semester, finding their errors wasn't hard at all and was one of the most fun parts. This one, however, has me stumped....
tromba is offline   Reply With Quote
Old May 4th, 2007, 9:06 AM   #6
tromba
Newbie
 
Join Date: Sep 2006
Posts: 12
Rep Power: 0 tromba is on a distinguished road
Quote:
Originally Posted by titaniumdecoy View Post
if (icecream == "fudge" || icecream == "rum" || icecream = "apple")
Since I'm somewhat new at this, would an error like this make the program not run, or would it just be a problem if the Apple button was pushed (still working fine for Fudge or Rum?
Quote:
Originally Posted by titaniumdecoy View Post
if (gallons == 5)s
I'd seen that s before... even removed it didn't seem to matter. I keep working with her most recent version of the program.
Quote:
Originally Posted by titaniumdecoy View Post
You might want to check out JSLint.
Now that's a nice site!!!! so here's a question on an error. To help make their code more individual (translated as can't copy code as easily] they have to comment what all parts of the program do. For these <input .... onClick -- it WORKS this way (or I should say displays correctly since the program doesn't work)
              <td><input type=button value="1" onClick ='gallons = 1; alert ("gallons is" + gallons); 
//This sets the variable for gallons and triggers an alert to display the number of gallons chosen.
'>
but JSLint says that there's an unclosed string and shows this: " <td><input type=button value="1" onClick ='gallons = 1; alert (..." -- I THINK it's refering to 'gallons but it's not a string but part of the onClick.

The problem may come when the //comment... follows in part of the onClick. I thought that //comment.... made what followed the // be ignored for the rest of the line, and put the '> on a new line. Is this correct? If so, what's the error on that line? JSLint won't run past this line....
tromba is offline   Reply With Quote
Old May 4th, 2007, 4:40 PM   #7
titaniumdecoy
Expert Programmer
 
titaniumdecoy's Avatar
 
Join Date: Nov 2005
Posts: 856
Rep Power: 3 titaniumdecoy is on a distinguished road
Send a message via AIM to titaniumdecoy
Quote:
Originally Posted by tromba View Post
The problem may come when the //comment... follows in part of the onClick. I thought that //comment.... made what followed the // be ignored for the rest of the line, and put the '> on a new line. Is this correct? If so, what's the error on that line? JSLint won't run past this line....
Carriage returns within the code snippet cause that JSLint error. Most browsers will probably have no problem interpreting that code, however.

The comment in the example you gave is, in DaWei's words, "trashing up the joint." Anyone with a cursory understanding of JavaScript will understand what an assigment operator and an alert statement do. As such, short code snippets enclosed in HTML attribute tags should not be commented in most cases. If you need to perform a more complex action (that may need commenting) you should use a function defined elsewhere, i.e., inside <script> tags. For example, onclick="doSomething();".
titaniumdecoy is offline   Reply With Quote
Old May 4th, 2007, 5:20 PM   #8
tromba
Newbie
 
Join Date: Sep 2006
Posts: 12
Rep Power: 0 tromba is on a distinguished road
Quote:
Originally Posted by titaniumdecoy View Post
Carriage returns within the code snippet cause that JSLint error. Most browsers will probably have no problem interpreting that code, however.
OK. The alerts and comments were added after the fact... in other words before they were added it still didn't work.

The reason for having a long list of what happens on the TOTAL button (or other onClick) is that this is the way the example in the book did it. That example in the book, from which the student adapted their program is this one.
tromba is offline   Reply With Quote
Old May 4th, 2007, 5:38 PM   #9
tromba
Newbie
 
Join Date: Sep 2006
Posts: 12
Rep Power: 0 tromba is on a distinguished road
Quote:
Originally Posted by titaniumdecoy View Post
Carriage returns within the code snippet cause that JSLint error. Most browsers will probably have no problem interpreting that code, however.
I tried to take out the carriage returns, but that's WAY too much trouble, given the model (see message above) that the students are working with.

Given that, JSLint seems to not be a possibility with this project.

So I'm still stuck on why the TOTAL button doesn't work from the original....
tromba is offline   Reply With Quote
Old May 4th, 2007, 8:39 PM   #10
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by tromba View Post
I tried to take out the carriage returns, but that's WAY too much trouble, given the model (see message above) that the students are working with.
Carriage returns are not the cause of the error. JSLint is a good tool, but it is very strict about what it considers to be valid. Any browser will be far more forgiving. For the purposes of teaching, I'd hesitate to use JSLint, as you'll likely spend more time trying to satisfy JSLint's exacting demands, than you will actually teaching the subject.

I personally would recommend Firebug. It's an add-on for the Firefox web browser, and is something I consider essential for debugging any piece of Javascript. If it is possible to use it (I know not all computers have Firefox installed on them), then I'd advise doing so.

Quote:
Originally Posted by tromba View Post
So I'm still stuck on why the TOTAL button doesn't work from the original....
This is a common problem for those beginning programming. To understand the problem, you need to understand the difference between assignment and equality.

An example of assignment:
x = 10
You can think of this as putting the number 10 in a box labelled "x".

An example of equality:
x == 10
You can think of this as testing to see whether the value in "x" is equal to the number 10.

The code does not work because the student has written:
icecream == "fudge" || icecream == "rum" || icecream = "apple"
Instead of:
icecream == "fudge" || icecream == "rum" || icecream == "apple"
(The part that causes an error is highlighted in red.)

In other words, the student is trying to put the value "apple" into the variable "icecream" (assignment). What they want to do is test whether the variable "icecream" has the value "apple" inside of it (equality).

Does that make sense?
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
I Require A Solution - Referencing Classes Sane C++ 15 Jul 4th, 2006 12:55 PM
can some one give me an approach to the solution lakshmikar Existing Project Development 0 Feb 9th, 2006 1:00 AM
A py2exe solution Sane Python 4 Dec 7th, 2005 4:27 PM
Bigger solution than needed LegionZero Coder's Corner Lounge 7 Aug 30th, 2005 11:35 PM
Easy solution I'm sure... tooliscrowned C++ 7 Apr 12th, 2005 2:48 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:10 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC