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 JavaScript Basics (Retired) Working With Numbers Doing Math

Anthony Harley
Anthony Harley
8,993 Points

Problem from school

I got a problem from school but not sure how to tackle it. I just started the program.

  1. Within the function, create the formula so that when more money is added to the account, it is added to the current balance.
  2. Write an if statement that outputs the balance to the screen if the deposit is equal to or greater than $100. Use the document.write method to output the deposit and balance in a complete sentence. If the deposit is less than $100, use an alert box to output β€œYou did not deposit enough money”.

1 Answer

Steven Parker
Steven Parker
229,644 Points

In later stages of the JavaScript Basics course you're taking now, you'll learn about conditional statements and functions, which are what you need for these tasks.

Your first task seems to be an add-on to some other function requirements that aren't shown here. Those original requirements would be important for creating the additional code.

But the second task is reasonably easy with a conditional statement:

if (deposit >= 100)
    document.write("Your deposit was " + deposit + " and the balance is now " +  balance);
else
    alert("You did not deposit enough money");