Puzzled Prorammer

Ask questions about projects relating to: computer science or pure mathematics (such as probability, statistics, geometry, etc...).

Moderators: AmyCowen, kgudger, bfinio, MadelineB, Moderators

Locked
cheegrlcraz
Posts: 1
Joined: Tue Feb 12, 2008 6:28 pm
Occupation: Student
Project Question: Computer Science
Project Due Date: February 14, 2008
Project Status: I am conducting my experiment

Puzzled Prorammer

Post by cheegrlcraz »

I am doing the simple calculator writing project and i was wondering if there was any way to take all of the four functions (addition,subtraction, multiplication, and division) and make the correct answer appear in my answer box. I have an add and subtract button, but they both subtract. does anyone know how i could fix this so the functions would be used properly?
davidkallman
Former Expert
Posts: 675
Joined: Thu Feb 03, 2005 3:38 pm

Re: Puzzled Prorammer

Post by davidkallman »

Hi cheegrlcraz,

I'm assuming the project you're doing is the one at:
https://www.sciencebuddies.org/science- ... p001.shtml

If you look at that page, you'll notice two items:

1. There is a recommendation to use the firefox browser, rather than internet explorer.
2. There is large set of background items under:
"Terms, Concepts and Questions to Start Background Research."

There is obviously a "bug" (logic error) in your code, since it's not working and the project is doable. Without seeing your code, it's hard to know where the bug is. I'm NOT encouraging, however, that you post your code. First, go through your code using 1. and 2. above before asking for help.

Lastly, are you getting help? A javascript program is difficult for someone in grades K-5
Cheers!

Dave
fmcwilliams
Former Expert
Posts: 20
Joined: Tue Jan 08, 2008 12:49 pm
Occupation: Software Engineer
Project Question: n/a
Project Due Date: n/a
Project Status: Not applicable

Re: Puzzled Prorammer

Post by fmcwilliams »

Hi cheegrlcraz,

Like Dave, I assume you started with the "Writing a Simple Calculator Program with JavaScript" project on the Project Ideas page and if this is so then I suggest that you look at the example and then at your code to solve your problem with the add and subtract both doing subtractions. On the example page there is a routine called CalculateSum that does the addition. In your code you might have a similar routine to subtract the numbers and another one to add two numbers together. Obviously, when the subtract button is used the program behaves correctly, but look to see what your program is doing when you pick the add button. It might be calling the subtraction routine. Another possibility is that the routine to perform the addition is written incorrectly and is really subtracting. A close look at the code should allow you to find and fix this bug.

For making your answer always appear in your answer box no matter which operation you choose, I will also ask you to look at the example page. In the CalculateSum routine you will see the instruction "form.Answer.value = A + B;". This instruction is performing and addition of A and B, but it is also directing the program to put that answer into the form.Answer.value text box. You can use this same kind of instruction in all of your routines that perform the four different operations. That way your answer will always be displayed in your answer box.

This sounds like a great project. Have fun with it and good luck.
Regards,
Frank M
Locked

Return to “Grades K-5: Math and Computer Science”