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

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
231,110 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
231,110 Points

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

Looking great!