![]() |
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. |
You wouldn't happen to be 'her', would you? Just curious about the lapse.
|
Quote:
|
:
if (icecream == "fudge" || icecream == "rum" || icecream = "apple"):
if (gallons == 5)s |
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.... |
Quote:
Quote:
Quote:
:
<td><input type=button value="1" onClick ='gallons = 1; alert ("gallons is" + gallons); 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.... |
Quote:
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();". |
Quote:
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. |
Quote:
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.... |
Quote:
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:
An example of assignment: :
x = 10An example of equality: :
x == 10The code does not work because the student has written: :
icecream == "fudge" || icecream == "rum" || icecream = "apple":
icecream == "fudge" || icecream == "rum" || icecream == "apple"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? |
| All times are GMT -5. The time now is 2:09 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC