Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.


Danny Percy
Danny Percy
3,719 Points

Is my code okay? Do.. while loops?

Hey guys! I just finished the 'do, while loops' and I am not sure that this code is good enough? How would you improve it? Thanks for help! :)

var drink;
var food;
var answer=false;

  drink=prompt('What do you want to drink sir?');
  food=prompt('What do you want to eat sir?');
//If the prompt is empty, than answer stays false
  if (drink===''){
    alert('Type something to drink!');
  }else if(food===''){
    alert('Type something to eat!');

  document.write('You have ordered ' + drink + ' and ' + food);

1 Answer

Cory Harkins
Cory Harkins
16,487 Points

That's pretty good, now build a more complex program that takes your customers order, and spits back a total price for the goods requested.

Build an array of items and prices, then test the user input against the items in the array to calculate the total. :)

Danny Percy
Danny Percy
3,719 Points

Thanks for the fast reply! Right now I am learning about Arrays.. can't wait to finish the code haha