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 Loops, Arrays and Objects Simplify Repetitive Tasks with Loops `do ... while` Loops

Why add unnecessary conditions as the instructor showed in the video! Check my code!

function randomNumber(upper) { return Math.floor(Math.random() * upper ) + 1; }

var totalGuesses = 0; do{ var value = parseInt(prompt("Guess a number from 1-10")); totalGuesses +=1; }while(value!==randomNumber(10)) // Isn't it right? document.write("<h2> It took you " + totalGuesses + " attempts to guess the number" );

1 Answer

Otto linden
Otto linden
5,857 Points

Your code is right! But the code showed in the video is easier to read and understand! Plus it’s easier to fix bugs in the code showed in the video! ??? (If you want you can mark this with ”the best answer” ?)