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 trialAmber Wells
Front End Web Development Techdegree Student 18,493 PointsWhen it comes to writing out the code, is there a better time to use alert vs. console.log vs. document.write etc.?
Aside from the obvious. It seems you can make it easier or harder on yourself, I noticed people using alert encountering more problems
2 Answers
Ken Stone
29,703 Pointsalert: When you want to alert the user to something like 'unable to connect to database please try again later' console.log: for debugging messages or other error conditions you may not want the user to see document.write: when you are adding content to the page.
Dan Oswalt
23,438 Pointsconsole.log.... if you're coding something for a user, you're not going to be using alert or document.write in most serious programs. You can use whatever you like if you're debugging, but logging things to the console is going to be the slickest way to go for most solutions. alert and document.write are often going to be used in tutorials as a quick and dirty way of displaying something in the interface itself.