Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Need help with java script homework

1. ## 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
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);

}

• 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.

• 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?

• 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

• Philip: You missed the first line of his code:
Code:
` br = "<br />";`
So his use of br as a variable there is fine.

• 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.)

•