...

View Full Version : Coding newbie needs help with a "calculator"



steve0827
12-10-2011, 08:56 PM
Hey everyone,
I've just joined up because I need some help. I'm just learning html, css, and javascript in a class so I don't know all too much. What I'm trying to do right now is create a function that I can calculate a number with.


There would be a blank "form" line where the person could enter a number(let's say 5000).
Then there would be another "form" line where the person could enter a percentage(let's say 10% or .1).
Then there would be a button that the person could click that would pop up an alert reading off what the answer would be(500). In an ideal world the second form line would be a drop down list and whatever is chosen would have a percentage tied to it that would be used when multiplied(I guess this would be more like a variable?)


This is for a project where the best website in the class gets an automatic A and does not have to take the final exam, so I'm really trying to impress.
I have no idea where to start, so I'd appreciate any help I can get.....if it's possible that is.

Logic Ali
12-10-2011, 09:22 PM
I'm trying to do right now is create a function that I can calculate a number with.
....
I have no idea where to start, so I'd appreciate any helpTry clicking on 'Search', specify just this forum and enter the word 'calculator'.

xelawho
12-10-2011, 09:24 PM
This is for a project where the best website in the class gets an automatic A and does not have to take the final exam, so I'm really trying to impress.
I have no idea where to start, so I'd appreciate any help I can get.....if it's possible that is.

well, it's possible, but here's the thing:
the forum guidelines warn against posting homework assignments. most people tend to take the wide view and help out on specific problems but balk against writing code from scratch. And being that, as you say, really impressive code will help you avoid taking the final exam, helping you out like this pretty much guarantees that you won't learn anything, doesn't it?

the place to start is to get your html in order. if you google w3schools and "html forms" you will find how to make buttons, inputs, select boxes, etc (do they really not teach you this?). from there you can google to find how to extract a variable value from a form element and then use the JS Math() function to perform calculations.

and if you get stuck along the way, feel free to post some code and ask some specific questions. :thumbsup:

Old Pedant
12-11-2011, 06:31 AM
I guess I'll point out one thing. It's obvious to us, but may not be to a newbie, as so few tutorial sites do it.

In a <select>, the value of each <option> does *NOT* have to be what the user sees on the screen!

Example:


<select name="planets">
<option value="">--select a planet--</option>
<option value="8"> Mercury </option>
<option value="6"> Venus </option>
<option value="5"> Earch </option>
<option value="7"> Mars </option>
<option value="1"> Jupiter </option>
<option value="2"> Saturn </option>
<option value="3"> Uranus </option>
<option value="4"> Neptune </option>
</select>

I assume you can figure out what the number assigned to each planet means?

Philip M
12-11-2011, 09:02 AM
It is not really in your best interests that others do your all or most homework for you. Your teacher may gain a false and exaggerated idea of your programming capabilities and so not offer you the support you need. Also, if you hand in other people's work which you do not completely understand, then you will start to fall behind and your difficulties will increase.

And, to put it bluntly, it is dishonest to pretend that the work is your own, especially as you admit that "have no idea where to start".

steve0827
12-12-2011, 04:20 AM
I'm not trying to ask someone to do my homework for me.....all I said is that " I have no idea where to start, so I'd appreciate any help I can get".

I'm trying to ask where I should start or if I could get any hints.....I probably should have clearly said that though.

Old Pedant
12-12-2011, 06:16 AM
I gave you a pretty big hint with the info about <select>.

Maybe you should try to create at least the HTML page with the <form>.

Until you do that, you can't start writing JavaScript.

steve0827
12-12-2011, 08:27 AM
I gave you a pretty big hint with the info about <select>.

Maybe you should try to create at least the HTML page with the <form>.

Until you do that, you can't start writing JavaScript.

You did, and it helped a lot. I ended up figuring everything out, albeit I did change it slightly and made the ending number show up in an alert pop-up. So thank you to those who helped.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum