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 trial

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

drew s
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
drew s
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
231,269 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.