Go Back   Computer Forums > Web Design | Website Development > Web Programming
Click Here to Login
Join Computer forums Today


Reply
 
Thread Tools Search this Thread Display Modes
 
Old 11-26-2014, 05:06 AM   #11
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: (sqrt) √ function: Javascript/HTML help

however that's still wrong,

you'll notice that now, we start of with 0 inside register_a, then when we press a number (1 for example) we end up with 01 rather than just the 1 that we were hoping for.

What we need to do is check if the value of register_a is a zero, and if it is just put the input data into that variable rather than concatenating it.

so we can change that function to

Code:
function input(num) {
if (register_a > 0) {
register_a = "" + register_a + num;
    }
else {
    register_a = num;
        }
document.getElementById("screen").innerHTML = register_a;
}
so that's a very simple way of getting data onto the screen...

and yet it's still not quite right, because user testing is going to show you that the original behaviour wasn't wrong for all cases.
when you use a calculator, if you just turned it on and there is a zero displayed on the screen.

If you type .5 you want 0.5 to be displayed, that was working and this fix broke that.

Still at the beginning I said that you needed to understand how a calculator worked, and I haven't really gone over that.

the point this far was to show that, even though you can approach things sensibly, if you don't have a design then you end up testing and finding a whole bunch of stuff that doesn't work.

all these things are being found AS they are coded because the program seems pretty simple, it's easy to just save that javascript and press a button and you get an instant hit on the results.

but if you were writing a more complicated program, or had not been able to test as you go, then you could find that a really small slip up actually really ruins stuff at the end!


if makes sense to break the program down into sections and to design each section.
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 11-26-2014, 05:28 AM   #12
Site Team
 
root's Avatar
 
Join Date: Mar 2004
Posts: 8,004
Default Re: (sqrt) √ function: Javascript/HTML help

User interface,
this is the simplest part of the calculator really because it's largely already standardised, I'm going to group numbers 1-9 into a 3x3 pad, and put a zero and decimal point underneath those number,

I have four basic functions, + - * / so I'll stick these down the side all in 1 column, then I have a space space underneath the 3 so I'll just jam the equals button in there.

Obviously I had thought about this before I just banged a load of code out.
I didn't draw it out.

You *may* find it beneficial to have a design, whether that's a rough design on a napkin, or something in paint, something you've commissioned a graphic design agency to do, or something that your little brother or sister just really wants.

it just helps to know where you are going with something.



you may chose a different design, and that's fine you can put the buttons anywhere you like and in any order, they
__________________

__________________
I didn’t fight my way to the top of the food chain to be a vegetarian…
Im sick of people saying 'dont waste paper'. If trees wanted to live, they'd all carry guns.
"The inherent vice of capitalism is the unequal sharing of blessings; The inherent vice of socialism is the equal sharing of miseries."
root is offline   Reply With Quote
Old 11-26-2014, 09:38 AM   #13
Solid State Member
 
Join Date: Sep 2014
Location: US
Posts: 13
Default Re: (sqrt) √ function: Javascript/HTML help

Root,

This information you gave me is absolutely brilliant. I am going to study the code you wrote and "back track" and to determine the exact steps I took to build the calculator. Your comments are helpful in figuring out what needs to be done, where I need to call on a function and what parts of code are missing.
The way you mapped out this code is excellent. I see a flow and a step-by-step format and using the advanced functions later. The comments area is understandable(I need to use it more)because it helps me understand why I wrote a specific code and how the code functions in human language. The part where you said "even though you can approach things sensibly, if you don't have a design then you end up testing and finding a whole bunch of stuff that doesn't work." That seems to be theme of what's going on with this sqrt root function.

Thanks for referring me to the color coded text editor Turbopad. I am going to download it. It is going to be more useful than notepad++.
However, I am not going to depend on color-coded text as a crutch either.
I can see that my "thinking" was all over the map when building this calculator. I was putting the cart before the horse in many instances. For example, making it work correctly before making it pretty with colors.

The format and information you gave me is invaluable and I'm going to refer and study your posts again. Until then I will keep persisting.....
__________________

jcrew is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT -5. The time now is 06:02 AM.


Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0