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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help with java script homework

    ok so the question is If they signed $175,000 worth of deals in the latest quarter they will be given a bonus of $5,000. If they signed $100,000 or more but less than $175,000 then they will get a bonus of $2,500 plus 1% of the amount they signed.
    Those who did not achieve $100,000 worth of signed agreements are still eligible for a $1,000 bonus if they signed 10% more than they did in the previous quarter.

    What I need HELP with is how to add the deals + bonus + % and display the total.


    my code so far - br = "<br />";
    var bonus;
    var deals;
    var total;

    //input
    name = prompt("Enter your name:");
    deals = prompt("Enter how many Deals in Dollars:");

    //process


    if (deals >= 175000) {
    total = deals + 5000
    document.write("total amount: " + total + br);

    }
    else if (deals >=100000 && deals <=175000) {
    total = deals + 2500 * 0.01
    document.write("total amount: " + total + br);

    }

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,623
    Thanks
    0
    Thanked 645 Times in 635 Posts
    Is this a "history of JavaScript" class?

    document.write is as dead as Netscape 4 and prompt has only been used for debugging since then. Neither would be used any more even in a beginners JavaScript class teaching programming.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New to the CF scene
    Join Date
    Sep 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well this is my first year in programming and this is the way our professor taught us, but could you help me out this with?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,918
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    I am afraid that your professor is many years behind the times. Does your college also teach out-of-date law, medicine, electronics or whatever?

    document.write("total amount: " + total + br);

    Check the syntax for an HTML line break.

    total = deals + 5000

    The + sign concatenates two string values. You must convert the string value deals into a number by one of several different methods.

    You have specified deals both as >=175000 and <=175000. So what if deals value is 175000?

    When requesting help from strangers it is always a good idea to remember the word "please".

    You may be able to hear, just out of earshot, the Town Crier .... BBC reporter
    Last edited by Philip M; 09-29-2013 at 07:55 AM.

    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.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Philip: You missed the first line of his code:
    Code:
     br = "<br />";
    So his use of br as a variable there is fine.
    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.

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,189
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    It looks like maybe you need to go back and take a course in PRE-algebra.

    Question: What is the value of the expression
    Code:
        3 + 4 * 5
    ???

    If you answered 35, then indeed it is time to go back to junior high school, at least.

    Multiplication has a higher precedence than addition. So the correct value of that expression is 23.

    That is, you must do the multiply (4*5) first and *THEN* do the addition.

    ********

    So now look at your code:
    Code:
        total = deals + 2500 * 0.01
    The multiply will take place first (2500 * 0.01, giving you 25) and then the addition, so your total will always be just 25 more than deals.

    (And that assumes you read what Philip wrote and converted deals to a number before trying to add to it.)
    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.


  •  

    Tags for this Thread

    Posting Permissions

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