Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Creating a JS function that uses math to define how close a purchase is to the next pricing tier. I've tried and failed.

<script> var money = 100; if( money > 100 ) { document.write("<b> You are recieve 10% off! </b>"); } else { if (money < 100 ) { document.write("<b> Spend X and receive 10% off!</b>"); } } </script>

I'm not sure how to make it calculate what the remainder is that is needed to be spend to reach the $100 mark.

1 Answer

  1. (if money > 100) should be (if money >= 100)
  2. you don't need the second if statement inside the else (if money < 100)

I am assuming that the variable money holds the total of the shopping cart, correct? so you are not actually assigning it the value 100 manually, correct?

in this case, here is how i think it should be implemented

<script> var money = 100; if( money > 100 ) { document.write("<b> You are recieve 10% off! </b>"); } else {  document.write("<b> Spend " + {100 - money} + " and receive 10% off!</b>"); }  </script>

You need to replace X with { 100 - money } to calculate the needed amount for the discount. hope this helps, good luck :)

Thank you! Much appreciated.