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

Clinton Hopgood
Clinton Hopgood
7,825 Points

Loop with user input

I'm trying to create a loop that waits for user input before each turn.

I would like the i to increase by 1 each turn up to a maximum of 9.

This is how my code looks without the loop.

<code> var turnByTurn = function() { i = 1; // loop turns if (i%2 == 0) { console.log("even"); turn1(); } else { console.log("odd") turn2(); } }; </code>

1 Answer

Clinton Hopgood
Clinton Hopgood
7,825 Points

I moved i outside of the function and added i++ to the function. This has solved the problem, however I'm interested to know if I can add user input to a loop.