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 trialatoniolo
9,216 PointsHow does he declare the prompt variable and without writing a command for the prompt the prompt still runs?
In the video, Dave declares a variable named search, and in the variable he puts a prompt command. My question is how he got the command to run without writing the command. Maybe I am confused if you declare a variable and assign a method or command to it and it runs or not.
1 Answer
Steven Parker
231,275 PointsIf you call a method or function (using parentheses after the name) to assign a variable, then that method/function code runs before the assignment is made.
Calling a method or function in a statement by itself is only useful if the method/function does not return a value. If it did, then without an assignment the return value would be lost.
atoniolo
9,216 Pointsatoniolo
9,216 PointsThank you that helps!