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.

JavaScript JavaScript and the DOM (Retiring) Responding to User Interaction Events and Functions as Parameters Review

Felix Andrew Sapalaran
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Felix Andrew Sapalaran
Python Development Techdegree Graduate 19,491 Points

JavaScript

How would you set the following function ‘add’ up to run after 5 seconds pass, using Window.setTimout? In addition, how would you pass ‘add’ the arguments 2 and 2 when it runs?

function add(num1, num2){ console.log(num1 + num2);

2 Answers

Steven Parker
Steven Parker
210,425 Points

This is a great opportunity to practice using the documentation. Take a look at the MDN page for setTimeout(), and pay particular attention to what arguments it takes and in which order.

Then it should be pretty easy to spot the correct answer in the quiz.

window.setTimeout(add,5000,2,2);. The window.setTimeout(add(2,2),5000); can seem like the first choice, but working through the function, it would first executed the add function with the parenthesis and then wait five seconds. This isn't what the question is asking for which makes the first option correct.