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 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” ?)