Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Coding newbie needs help with a "calculator"

    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.

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Quote Originally Posted by steve0827 View Post
    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 help
    Try clicking on 'Search', specify just this forum and enter the word 'calculator'.

  • #3
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,762
    Thanks
    55
    Thanked 517 Times in 514 Posts
    Quote Originally Posted by steve0827 View Post
    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.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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:
    Code:
    <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?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,730
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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".

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #6
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #8
    New to the CF scene
    Join Date
    Dec 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •