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!

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


Mattheus de Oliveira Machado
Mattheus de Oliveira Machado
737 Points

Code validation

How treehouse make that code challenges? I think they use javascript to validate the codes that we type but how validate that codes?

1 Answer

My guess is that JavaScript sends an Ajax request to the Treehouse server with your code in it. Treehouse has various programs set up there that either (1) analyze that code to make sure you've properly typed something out, or (2) actually evaluate or run your code to see if it works. In either case, if the code passes, then the Ajax request returns a yes, allowing you to proceed with the challenge.

I distinguish #1 and #2 from each other because I've passed a challenge before using an answer I knew would work, though it wasn't technically what the challenge engine was looking for. In those cases, the engine just flat-out evaluated my code and decided that it worked (#2). Other times, my syntax would be correct and would work properly in a real-life setting, but the engine would fail me because I padded my function calls with spaces or something like that, and it tripped up on those. In that case, the engine actually looked at my code to determine if I had passed, instead of actually evaluating it (#1).

The challenge engine isn't perfect, but it's pretty darn good and extremely effective too. Better than anything I could do, for certain.