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

How about this code of mine?

var randomNumber = getRandomNumber(10); var guess; var guessCount = 0;

function getRandomNumber( upper ) { var num = Math.floor(Math.random() * upper) + 1; return num; }

do { guess = parseInt(prompt (' I\'m thinking of a number, please think')); guessCount += 1; } while( guess !== randomNumber); document.write ('<p> ' + 'Good job! </p>'); document.write ('you have succesfully guessed the number in ' + guessCount + ' attempts');

2 Answers

Steven Parker
Steven Parker
216,718 Points

I'm not sure what you're asking, but at first glance this code appears to be complete and correct. Good job. :+1:

Tip: You can avoid escaping apostrophes by enclosing strings in quote marks instead:   "Here's an example"

And for future posts with code, be sure to use the instructions for code formatting in the Markdown Cheatsheet pop-up below the "Add an Answer" area. :arrow_heading_down:   Or watch this video on code formatting.

Whoaaa, thanks for the response sir. As for the code formatting rules, I'll read it immediately.

Steven Parker
Steven Parker
216,718 Points

Bonus tip: You never need concatenation with two literal strings. Just write them as one string:   "<p> Good job! </p>"

Looking great!