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;
do you understand how if/them/else works?
yea but with the math it makes it confusing
Okay great. So according to the value you have for salesCost, which condition is going to be executed?
sales total I think but yet not sure which number
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?
the 1.5 one
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?
yes thank you for your help
You are very welcome.
Join our real-time social learning platform and learn together with your friends!