Ask your own question, for FREE!
Computer Science 7 Online
OpenStudy (anonymous):

I need help with JavaScript. The value of salesCost is 20. After the following code executes, what is the value of salesTotal? if (salesCost <= 25) salesTotal = salesCost * 1.5; else salesTotal = salesCost * 1.25;

OpenStudy (jagatuba):

do you understand how if/them/else works?

OpenStudy (anonymous):

yea but with the math it makes it confusing

OpenStudy (jagatuba):

Okay great. So according to the value you have for salesCost, which condition is going to be executed?

OpenStudy (anonymous):

sales total I think but yet not sure which number

OpenStudy (jagatuba):

Ok you have two conditions that will be executed. salesTotal = salesCost * 1.5; OR salesTotal = salesCost * 1.25; Now look at your conditional statement: IF salesCost is less than or equal to 25 THEN salesTotal = salesCost * 1.5; OTHERWISE (else) salesTotal = salesCost * 1.25; Looking at it this way which calculation do you think will be performed?

OpenStudy (anonymous):

the 1.5 one

OpenStudy (jagatuba):

Please forgive my delay. I'm helping you as I cook dinner. lol You are correct. Since salesCost is 20 and 20 <25 then the first condition is going to execute. In that condition we have another variable salesTotal. To this variable we are assigning the value of salesCost times 1.5 OR salesTotal = 20*1.5 OR salesTotal = 30 Does that make sense?

OpenStudy (anonymous):

yes thank you for your help

OpenStudy (jagatuba):

You are very welcome.

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!